Skip to content

Commit

Permalink
Merge branch 'master' into che-java-test-runner
Browse files Browse the repository at this point in the history
Signed-off-by: Mirage Abeysekara <mirage.12@cse.mrt.ac.lk>
  • Loading branch information
Mirage20 committed Jun 9, 2016
2 parents e8840a6 + 7d17a4c commit 8b47d87
Show file tree
Hide file tree
Showing 22 changed files with 543 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.eclipse.che.api.git.LocalGitUserResolver;
import org.eclipse.che.git.impl.nativegit.NativeGitConnectionFactory;
import org.eclipse.che.inject.DynaModule;
import org.eclipse.che.plugin.java.server.rest.WsAgentURLProvider;
import org.eclipse.che.security.oauth.RemoteOAuthTokenProvider;
import org.everrest.core.impl.async.AsynchronousJobPool;
import org.everrest.core.impl.async.AsynchronousJobService;
Expand Down Expand Up @@ -79,6 +80,9 @@ protected void configure() {

bind(String.class).annotatedWith(Names.named("event.bus.url")).toProvider(EventBusURLProvider.class);
bind(ApiEndpointAccessibilityChecker.class);

bind(String.class).annotatedWith(Names.named("wsagent.endpoint"))
.toProvider(WsAgentURLProvider.class);
}

//it's need for WSocketEventBusClient and in the future will be replaced with the property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ machine.docker.local_node_host=NULL
# otherwise workspace snapshots would be saved locally.
machine.docker.snapshot_use_registry=false

# Allows to adjust machine swap memory by multiplication current machnine memory on provided value.
# default is 0 which means disabled swap, if set multiplier value equal to 0.5 machine swap will be
# configured with size that equal to half of current machine memory.
machine.docker.memory_swap_multiplier=0

# URL path to api service.
# Browser clients use this to initiate REST communications with workspace master
api.endpoint=http://localhost:${SERVER_PORT}/wsmaster/api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ public static Link createLink(String method, String href, String rel) {
return DtoFactory.getInstance().createDto(Link.class).withMethod(method).withHref(href).withRel(rel);
}

public static Link createLink(String method, String href, String rel, List<LinkParameter> params) {
return DtoFactory.getInstance()
.createDto(Link.class)
.withMethod(method)
.withHref(href)
.withRel(rel)
.withParameters(params);
}

private LinksHelper() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2012-2016 Codenvy, S.A.
* 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:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.ide.api.machine;

import com.google.inject.Singleton;

/**
* Dummy implementation.
*
* @author Anton Korneta
*/
@Singleton
public class CheWsAgentLinksModifier implements WsAgentURLModifier {

@Override
public void initialize(DevMachine devMachine) {
}

@Override
public String modify(String agentUrl) {
return agentUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public String getWsAgentWebSocketUrl() {
}
}
//should not be
final String message = "Reference " + Constants.WSAGENT_REFERENCE + " not found in DevMachine description";
final String message = "Reference " + Constants.WSAGENT_WEBSOCKET_REFERENCE + " not found in DevMachine description";
Log.error(getClass(), message);
throw new RuntimeException(message);
}
Expand All @@ -82,7 +82,7 @@ public String getTerminalUrl() {
}
}
//should not be
final String message = "Reference " + Constants.WSAGENT_REFERENCE + " not found in DevMachine description";
final String message = "Reference " + Constants.TERMINAL_REFERENCE + " not found in DevMachine description";
Log.error(getClass(), message);
throw new RuntimeException(message);
}
Expand Down Expand Up @@ -130,4 +130,7 @@ public String getId() {
return devMachineDescriptor.getId();
}

public List<Link> getDevMachineLinks() {
return devMachineLinks;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (c) 2012-2016 Codenvy, S.A.
* 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:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.ide.api.machine;


/**
* Modify the URL to the workspace agent.
* <p>Note that for che assembly it's return the source url.
*
* @author Anton Korneta
*/
public interface WsAgentURLModifier {

/**
* Initializes modifier during the start of the workspace
*
* @param devMachine
* runtime information of dev machine instance, such as link
*/
void initialize(DevMachine devMachine);

/**
* Change source url in accordance with the requirements of the assembly
*
* @param agentUrl
* any url to the workspace agent
* @return modified url
*/
String modify(String agentUrl);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.app.CurrentProject;
import org.eclipse.che.ide.api.machine.WsAgentURLModifier;
import org.eclipse.che.ide.api.project.node.HasStorablePath;
import org.eclipse.che.ide.api.selection.Selection;
import org.eclipse.che.ide.download.DownloadContainer;
Expand All @@ -42,13 +43,15 @@ public class DownloadAsZipAction extends AbstractPerspectiveAction {
private final AppContext appContext;
private final DownloadContainer downloadContainer;
private final ProjectExplorerPresenter projectExplorer;
private final WsAgentURLModifier wsAgentURLModifier;

@Inject
public DownloadAsZipAction(AppContext appContext,
CoreLocalizationConstant locale,
Resources resources,
DownloadContainer downloadContainer,
ProjectExplorerPresenter projectExplorer) {
ProjectExplorerPresenter projectExplorer,
WsAgentURLModifier wsAgentURLModifier) {
super(Arrays.asList(PROJECT_PERSPECTIVE_ID),
locale.downloadProjectAsZipName(),
locale.downloadProjectAsZipDescription(),
Expand All @@ -57,13 +60,14 @@ public DownloadAsZipAction(AppContext appContext,
this.appContext = appContext;
this.downloadContainer = downloadContainer;
this.projectExplorer = projectExplorer;
this.wsAgentURLModifier = wsAgentURLModifier;
}

/** {@inheritDoc} */
@Override
public void actionPerformed(ActionEvent e) {
String url = appContext.getDevMachine().getWsAgentBaseUrl() + "/project/export/" + getPath();
downloadContainer.setUrl(url);
downloadContainer.setUrl(wsAgentURLModifier.modify(url));
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.web.bindery.event.shared.EventBus;

import org.eclipse.che.ide.api.machine.DevMachine;
import org.eclipse.che.ide.api.machine.WsAgentURLModifier;
import org.eclipse.che.ide.api.machine.WsAgentStateController;
import org.eclipse.che.api.machine.shared.dto.MachineDto;
import org.eclipse.che.api.promises.client.Operation;
Expand Down Expand Up @@ -62,6 +63,7 @@ public class BootstrapController {
private final AppContext appContext;
private final WorkspaceServiceClient workspaceService;
private final Provider<WsAgentStateController> wsAgentStateControllerProvider;
private final WsAgentURLModifier wsAgentURLModifier;

@Inject
public BootstrapController(Provider<WorkspacePresenter> workspaceProvider,
Expand All @@ -71,14 +73,16 @@ public BootstrapController(Provider<WorkspacePresenter> workspaceProvider,
AppContext appContext,
DtoRegistrar dtoRegistrar,
WorkspaceServiceClient workspaceService,
Provider<WsAgentStateController> wsAgentStateControllerProvider) {
Provider<WsAgentStateController> wsAgentStateControllerProvider,
WsAgentURLModifier wsAgentURLModifier) {
this.workspaceProvider = workspaceProvider;
this.extensionInitializer = extensionInitializer;
this.eventBus = eventBus;
this.appStateManagerProvider = appStateManagerProvider;
this.appContext = appContext;
this.workspaceService = workspaceService;
this.wsAgentStateControllerProvider = wsAgentStateControllerProvider;
this.wsAgentURLModifier = wsAgentURLModifier;
appContext.setStartUpActions(StartUpActionsParser.getStartUpActions());
dtoRegistrar.registerDtoProviders();

Expand All @@ -103,6 +107,7 @@ public void apply(WorkspaceDto ws) throws OperationException {
appContext.setDevMachine(devMachine);
appContext.setProjectsRoot(devMachineDto.getRuntime().projectsRoot());
wsAgentStateControllerProvider.get().initialize(devMachine);
wsAgentURLModifier.initialize(devMachine);
startWsAgentComponents(components.values().iterator());
}
}).catchError(new Operation<PromiseError>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.eclipse.che.ide.upload.file;

import org.eclipse.che.ide.CoreLocalizationConstant;
import org.eclipse.che.ide.api.machine.WsAgentURLModifier;
import org.eclipse.che.ide.ui.window.Window;

import com.google.gwt.event.dom.client.ChangeEvent;
Expand Down Expand Up @@ -39,6 +40,8 @@ public class UploadFileViewImpl extends Window implements UploadFileView {
public interface UploadFileViewBinder extends UiBinder<Widget, UploadFileViewImpl> {
}

private final WsAgentURLModifier wsAgentURLModifier;

Button btnCancel;
Button btnUpload;

Expand All @@ -54,7 +57,9 @@ public interface UploadFileViewBinder extends UiBinder<Widget, UploadFileViewImp

/** Create view. */
@Inject
public UploadFileViewImpl(UploadFileViewBinder uploadFileViewBinder, CoreLocalizationConstant locale) {
public UploadFileViewImpl(UploadFileViewBinder uploadFileViewBinder,
CoreLocalizationConstant locale,
WsAgentURLModifier wsAgentURLModifier) {

this.setTitle(locale.uploadFileTitle());
setWidget(uploadFileViewBinder.createAndBindUi(this));
Expand All @@ -77,6 +82,7 @@ public void onClick(ClickEvent event) {
}
});
addButtonToFooter(btnUpload);
this.wsAgentURLModifier = wsAgentURLModifier;
}

/** Bind handlers. */
Expand Down Expand Up @@ -126,7 +132,7 @@ public void setEncoding(@NotNull String encodingType) {
/** {@inheritDoc} */
@Override
public void setAction(@NotNull String url) {
submitForm.setAction(url);
submitForm.setAction(wsAgentURLModifier.modify(url));
submitForm.setMethod(FormPanel.METHOD_POST);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.inject.Inject;

import org.eclipse.che.ide.CoreLocalizationConstant;
import org.eclipse.che.ide.api.machine.WsAgentURLModifier;
import org.eclipse.che.ide.ui.window.Window;

import javax.validation.constraints.NotNull;
Expand All @@ -39,6 +40,8 @@ public class UploadFolderFromZipViewImpl extends Window implements UploadFolderF
public interface UploadFolderFromZipViewBinder extends UiBinder<Widget, UploadFolderFromZipViewImpl> {
}

private final WsAgentURLModifier wsAgentURLModifier;

Button btnCancel;
Button btnUpload;
FileUpload file;
Expand All @@ -58,7 +61,8 @@ public interface UploadFolderFromZipViewBinder extends UiBinder<Widget, UploadFo
@Inject
public UploadFolderFromZipViewImpl(UploadFolderFromZipViewBinder uploadFileViewBinder,
CoreLocalizationConstant locale,
org.eclipse.che.ide.Resources resources) {
org.eclipse.che.ide.Resources resources,
WsAgentURLModifier wsAgentURLModifier) {
this.constant = locale;
this.setTitle(locale.uploadZipFolderTitle());
setWidget(uploadFileViewBinder.createAndBindUi(this));
Expand All @@ -82,6 +86,7 @@ public void onClick(ClickEvent event) {
});
btnUpload.addStyleName(resources.Css().buttonLoader());
addButtonToFooter(btnUpload);
this.wsAgentURLModifier = wsAgentURLModifier;
}

/** Bind handlers. */
Expand Down Expand Up @@ -143,7 +148,7 @@ public void setEncoding(@NotNull String encodingType) {
/** {@inheritDoc} */
@Override
public void setAction(@NotNull String url) {
submitForm.setAction(url);
submitForm.setAction(wsAgentURLModifier.modify(url));
submitForm.setMethod(FormPanel.METHOD_POST);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.gwtmockito.GwtMockito;
import com.google.gwtmockito.GwtMockitoTestRunner;

import org.eclipse.che.ide.api.machine.WsAgentURLModifier;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -39,18 +40,20 @@
@RunWith(GwtMockitoTestRunner.class)
public class UploadFileViewImplTest {

private UploadFileViewImpl view;
private UploadFileViewImpl view;

UploadFileViewImpl.UploadFileViewBinder binder;
CoreLocalizationConstant locale;
WsAgentURLModifier wsAgentURLModifier;

@Before
public void setup() {
GwtMockito.initMocks(this);
binder = GWT.create(UploadFileViewImpl.UploadFileViewBinder.class);
locale = GWT.create(CoreLocalizationConstant.class);
wsAgentURLModifier = GWT.create(WsAgentURLModifier.class);
UploadFilePresenter presenter = mock(UploadFilePresenter.class);
view = new UploadFileViewImpl(binder, locale);
view = new UploadFileViewImpl(binder, locale, wsAgentURLModifier);
view.setDelegate(presenter);
}

Expand All @@ -76,10 +79,11 @@ public void submitShouldBeExecuted() {
@Test
public void setActionShouldBeExecuted() {
view.submitForm = mock(FormPanel.class);
final String url = "url";
when(wsAgentURLModifier.modify(url)).thenReturn(url);
view.setAction(url);

view.setAction("url");

verify(view.submitForm).setAction(eq("url"));
verify(view.submitForm).setAction(eq(url));
verify(view.submitForm).setMethod(eq(FormPanel.METHOD_POST));
}

Expand Down
Loading

0 comments on commit 8b47d87

Please sign in to comment.