Skip to content

Commit

Permalink
Update project config when event is fired (#10677)
Browse files Browse the repository at this point in the history
Signed-off-by: Anatoliy Bazko <[email protected]>
  • Loading branch information
tolusha authored and tsmaeder committed Oct 17, 2018
1 parent 5be323e commit a694dfa
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static org.eclipse.che.api.languageserver.util.JsonUtil.convertToJson;
import static org.eclipse.che.jdt.ls.extension.api.Commands.CLIENT_UPDATE_PROJECT;
import static org.eclipse.che.jdt.ls.extension.api.Commands.CLIENT_UPDATE_PROJECTS_CLASSPATH;
import static org.eclipse.che.jdt.ls.extension.api.Commands.CLIENT_UPDATE_PROJECT_CONFIG;

import com.google.inject.Inject;
import com.google.inject.Singleton;
Expand Down Expand Up @@ -137,6 +138,7 @@ private ExecuteCommandParams convertParams(ExecuteCommandParams params) {
params.setArguments(fixedPathList);
break;
case CLIENT_UPDATE_PROJECT:
case CLIENT_UPDATE_PROJECT_CONFIG:
Object projectUri = params.getArguments().get(0);
params.setArguments(
singletonList(removePrefixUri(convertToJson(projectUri).getAsString())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-project-shared</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-workspace-shared</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-gwt</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@

import static org.eclipse.che.jdt.ls.extension.api.Commands.CLIENT_UPDATE_PROJECT;
import static org.eclipse.che.jdt.ls.extension.api.Commands.CLIENT_UPDATE_PROJECTS_CLASSPATH;
import static org.eclipse.che.jdt.ls.extension.api.Commands.CLIENT_UPDATE_PROJECT_CONFIG;

import com.google.gwt.json.client.JSONString;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.web.bindery.event.shared.EventBus;
import java.util.List;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.project.ProjectServiceClient;
import org.eclipse.che.ide.project.node.ProjectClasspathChangedEvent;
import org.eclipse.che.ide.resource.Path;
import org.eclipse.lsp4j.ExecuteCommandParams;

/**
Expand All @@ -32,11 +36,14 @@
public class ExecuteClientCommandProcessor {
private EventBus eventBus;
private AppContext appContext;
private final ProjectServiceClient projectService;

@Inject
public ExecuteClientCommandProcessor(EventBus eventBus, AppContext appContext) {
public ExecuteClientCommandProcessor(
EventBus eventBus, AppContext appContext, ProjectServiceClient projectService) {
this.eventBus = eventBus;
this.appContext = appContext;
this.projectService = projectService;
}

public void execute(ExecuteCommandParams params) {
Expand All @@ -49,6 +56,9 @@ public void execute(ExecuteCommandParams params) {
case CLIENT_UPDATE_PROJECT:
updateProject(stringValue(params.getArguments()));
break;
case CLIENT_UPDATE_PROJECT_CONFIG:
updateProjectConfig(stringValue(params.getArguments()));
break;
default:
break;
}
Expand All @@ -66,7 +76,31 @@ private void updateProject(String project) {
});
}

private void updateProjectConfig(String project) {
appContext
.getWorkspaceRoot()
.getContainer(project)
.then(
container -> {
projectService
.getProject(Path.valueOf(project))
.then(
projectConfigDto -> {
projectService
.updateProject(projectConfigDto)
.then(
arg -> {
if (container.isPresent()) {
container.get().synchronize();
}
});
});
});
}

private String stringValue(Object value) {
return value instanceof JSONString ? ((JSONString) value).stringValue() : String.valueOf(value);
return value instanceof JSONString
? ((JSONString) value).stringValue()
: (value instanceof List ? stringValue(((List) value).get(0)) : String.valueOf(value));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import org.eclipse.che.api.fs.server.FsManager;
import org.eclipse.che.api.project.server.ProjectManager;
import org.eclipse.che.api.project.server.ProjectService;
import org.eclipse.che.api.project.server.notification.PreProjectDeletedEvent;
import org.eclipse.che.api.project.server.notification.ProjectCreatedEvent;
import org.eclipse.che.api.project.server.notification.ProjectDeletedEvent;
import org.eclipse.che.api.project.server.notification.ProjectItemModifiedEvent;
Expand Down Expand Up @@ -237,6 +238,8 @@ public void delete(String wsPath)
wsPath = absolutize(wsPath);

if (projectManager.isRegistered(wsPath)) {
eventService.publish(new PreProjectDeletedEvent(wsPath));

projectManager
.delete(wsPath)
.map(RegisteredProject::getPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.che.api.core.ServerException;
import org.eclipse.che.api.core.notification.EventService;
import org.eclipse.che.api.project.server.ProjectManager;
import org.eclipse.che.api.project.server.notification.PreProjectDeletedEvent;
import org.eclipse.che.api.project.server.notification.ProjectDeletedEvent;
import org.eclipse.che.api.project.shared.RegisteredProject;
import org.eclipse.che.api.watcher.server.FileWatcherManager;
Expand Down Expand Up @@ -59,6 +60,8 @@ private void registerOperation() {
private void consumeDelete(String wsPath) {
try {
if (projectConfigRegistry.isRegistered(wsPath)) {
eventService.publish(new PreProjectDeletedEvent(wsPath));

projectConfigRegistry
.getAll(wsPath)
.stream()
Expand Down

0 comments on commit a694dfa

Please sign in to comment.