Skip to content
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

CHE-3659: Remove GDB debug configuration #4513

Merged
merged 1 commit into from
Mar 23, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,18 @@
*******************************************************************************/
package org.eclipse.che.plugin.gdb.ide.configuration;

import com.google.gwt.core.client.JsArrayMixed;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.inject.Inject;
import com.google.inject.Singleton;

import org.eclipse.che.api.core.model.machine.Machine;
import org.eclipse.che.api.core.model.workspace.Workspace;
import org.eclipse.che.api.machine.shared.dto.MachineDto;
import org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor;
import org.eclipse.che.api.promises.client.Operation;
import org.eclipse.che.api.promises.client.OperationException;
import org.eclipse.che.api.promises.client.Promise;
import org.eclipse.che.api.promises.client.js.Promises;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.debug.DebugConfiguration;
import org.eclipse.che.ide.api.debug.DebugConfigurationPage;
import org.eclipse.che.ide.api.machine.RecipeServiceClient;
import org.eclipse.che.ide.dto.DtoFactory;
import org.eclipse.che.ide.extension.machine.client.inject.factories.EntityFactory;
import org.eclipse.che.ide.extension.machine.client.command.macros.CurrentProjectPathMacro;
import org.eclipse.che.ide.json.JsonHelper;
import org.eclipse.che.ide.extension.machine.client.inject.factories.EntityFactory;

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -53,8 +44,6 @@ public class GdbConfigurationPagePresenter implements GdbConfigurationPageView.A
private final GdbConfigurationPageView view;
private final AppContext appContext;
private final EntityFactory entityFactory;
private final RecipeServiceClient recipeServiceClient;
private final DtoFactory dtoFactory;
private final CurrentProjectPathMacro currentProjectPathMacro;

private DebugConfiguration editedConfiguration;
Expand All @@ -66,15 +55,11 @@ public class GdbConfigurationPagePresenter implements GdbConfigurationPageView.A
@Inject
public GdbConfigurationPagePresenter(GdbConfigurationPageView view,
AppContext appContext,
DtoFactory dtoFactory,
EntityFactory entityFactory,
RecipeServiceClient recipeServiceClient,
CurrentProjectPathMacro currentProjectPathMacro) {
this.view = view;
this.appContext = appContext;
this.entityFactory = entityFactory;
this.recipeServiceClient = recipeServiceClient;
this.dtoFactory = dtoFactory;
this.currentProjectPathMacro = currentProjectPathMacro;

view.setDelegate(this);
Expand Down Expand Up @@ -124,16 +109,18 @@ public void go(AcceptsOneWidget container) {
}

private void setHosts(List<Machine> machines) {
List<Promise<RecipeDescriptor>> recipePromises = new ArrayList<>(machines.size());
Map<String, String> hosts = new HashMap<>();
for (Machine machine : machines) {
String location = machine.getConfig().getSource().getLocation();
String recipeId = getRecipeId(location);
recipePromises.add(recipeServiceClient.getRecipe(recipeId));
String host = machine.getRuntime().getProperties().get("network.ipAddress");
if (host == null) {
continue;
}

String description = host + " (" + machine.getConfig().getName() + ")";
hosts.put(host, description);
}

@SuppressWarnings("unchecked")
final Promise<RecipeDescriptor>[] recipePromisesArray = (Promise<RecipeDescriptor>[])recipePromises.toArray();
setHostsList(recipePromisesArray, machines);
view.setHostsList(hosts);
}

private List<Machine> getMachines() {
Expand All @@ -153,34 +140,6 @@ private List<Machine> getMachines() {
return machines;
}

private void setHostsList(final Promise<RecipeDescriptor>[] recipePromises, final List<Machine> machines) {
Promises.all(recipePromises).then(new Operation<JsArrayMixed>() {
@Override
public void apply(JsArrayMixed recipes) throws OperationException {
Map<String, String> hosts = new HashMap<>();

for (int i = 0; i < recipes.length(); i++) {
String recipeJson = recipes.getObject(i).toString();
RecipeDescriptor recipeDescriptor = dtoFactory.createDtoFromJson(recipeJson, RecipeDescriptor.class);

String script = recipeDescriptor.getScript();

String host;
try {
Map<String, String> m = JsonHelper.toMap(script);
host = m.containsKey("host") ? m.get("host") : "localhost";
} catch (Exception e) {
host = "localhost";
}
String description = host + " (" + machines.get(i).getConfig().getName() + ")";
hosts.put(host, description);
}

view.setHostsList(hosts);
}
});
}

@Override
public boolean isDirty() {
return !originHost.equals(editedConfiguration.getHost())
Expand Down Expand Up @@ -228,9 +187,4 @@ public void onDevHostChanged(boolean value) {
listener.onDirtyStateChanged();
}
}

private String getRecipeId(String location) {
location = location.substring(0, location.lastIndexOf("/"));
return location.substring(location.lastIndexOf("/") + 1);
}
}