CHE-5810: Improve client encoding for file or folder path to support special symbols (#6166)
parent
d14dae95c7
commit
d847b4149f
|
|
@ -15,8 +15,10 @@ import static java.util.stream.Collectors.toList;
|
|||
import static org.eclipse.che.api.git.shared.AddRequest.DEFAULT_PATTERN;
|
||||
import static org.eclipse.che.ide.MimeType.APPLICATION_JSON;
|
||||
import static org.eclipse.che.ide.MimeType.TEXT_PLAIN;
|
||||
import static org.eclipse.che.ide.resource.Path.valueOf;
|
||||
import static org.eclipse.che.ide.rest.HTTPHeader.ACCEPT;
|
||||
import static org.eclipse.che.ide.rest.HTTPHeader.CONTENTTYPE;
|
||||
import static org.eclipse.che.ide.util.PathEncoder.encodePath;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
|
@ -109,7 +111,8 @@ public class GitServiceClientImpl implements GitServiceClient {
|
|||
|
||||
@Override
|
||||
public Promise<Void> init(Path project, boolean bare) {
|
||||
String url = getWsAgentBaseUrl() + INIT + "?projectPath=" + project + "&bare=" + bare;
|
||||
String url =
|
||||
getWsAgentBaseUrl() + INIT + "?projectPath=" + encodePath(project) + "&bare=" + bare;
|
||||
return asyncRequestFactory.createPostRequest(url, null).loader(loader).send();
|
||||
}
|
||||
|
||||
|
|
@ -122,7 +125,7 @@ public class GitServiceClientImpl implements GitServiceClient {
|
|||
.withRemoteUri(remoteUri)
|
||||
.withWorkingDir(project.toString());
|
||||
|
||||
String params = "?projectPath=" + project;
|
||||
String params = "?projectPath=" + encodePath(project);
|
||||
String url = CLONE + params;
|
||||
|
||||
return asyncRequestFactory.createPostRequest(url, cloneRequest).loader(loader).send();
|
||||
|
|
@ -130,7 +133,7 @@ public class GitServiceClientImpl implements GitServiceClient {
|
|||
|
||||
@Override
|
||||
public Promise<String> statusText(Path project) {
|
||||
String params = "?projectPath=" + project;
|
||||
String params = "?projectPath=" + encodePath(project);
|
||||
String url = getWsAgentBaseUrl() + STATUS + params;
|
||||
|
||||
return asyncRequestFactory
|
||||
|
|
@ -148,7 +151,7 @@ public class GitServiceClientImpl implements GitServiceClient {
|
|||
paths == null
|
||||
? DEFAULT_PATTERN
|
||||
: stream(paths).map(path -> path.isEmpty() ? "." : path.toString()).collect(toList()));
|
||||
String url = getWsAgentBaseUrl() + ADD + "?projectPath=" + project;
|
||||
String url = getWsAgentBaseUrl() + ADD + "?projectPath=" + encodePath(project);
|
||||
return asyncRequestFactory.createPostRequest(url, addRequest).loader(loader).send();
|
||||
}
|
||||
|
||||
|
|
@ -160,7 +163,7 @@ public class GitServiceClientImpl implements GitServiceClient {
|
|||
.withMessage(message)
|
||||
.withAmend(amend)
|
||||
.withAll(all);
|
||||
String url = getWsAgentBaseUrl() + COMMIT + "?projectPath=" + project;
|
||||
String url = getWsAgentBaseUrl() + COMMIT + "?projectPath=" + encodePath(project);
|
||||
return asyncRequestFactory
|
||||
.createPostRequest(url, commitRequest)
|
||||
.loader(loader)
|
||||
|
|
@ -180,7 +183,7 @@ public class GitServiceClientImpl implements GitServiceClient {
|
|||
.map(Path::toString)
|
||||
.collect(toList()));
|
||||
|
||||
String url = getWsAgentBaseUrl() + COMMIT + "?projectPath=" + project;
|
||||
String url = getWsAgentBaseUrl() + COMMIT + "?projectPath=" + encodePath(project);
|
||||
|
||||
return asyncRequestFactory
|
||||
.createPostRequest(url, commitRequest)
|
||||
|
|
@ -190,7 +193,7 @@ public class GitServiceClientImpl implements GitServiceClient {
|
|||
|
||||
@Override
|
||||
public Promise<Map<String, String>> config(Path project, List<String> requestedConfig) {
|
||||
String params = "?projectPath=" + project;
|
||||
String params = "?projectPath=" + encodePath(project);
|
||||
if (requestedConfig != null) {
|
||||
for (String entry : requestedConfig) {
|
||||
params += "&requestedConfig=" + entry;
|
||||
|
|
@ -212,7 +215,7 @@ public class GitServiceClientImpl implements GitServiceClient {
|
|||
.withRemote(remote)
|
||||
.withRefSpec(refSpec)
|
||||
.withForce(force);
|
||||
String url = getWsAgentBaseUrl() + PUSH + "?projectPath=" + project;
|
||||
String url = getWsAgentBaseUrl() + PUSH + "?projectPath=" + encodePath(project);
|
||||
return asyncRequestFactory
|
||||
.createPostRequest(url, pushRequest)
|
||||
.send(dtoUnmarshallerFactory.newUnmarshaller(PushResponse.class));
|
||||
|
|
@ -222,7 +225,7 @@ public class GitServiceClientImpl implements GitServiceClient {
|
|||
public Promise<List<Remote>> remoteList(Path project, String remoteName, boolean verbose) {
|
||||
String params =
|
||||
"?projectPath="
|
||||
+ project
|
||||
+ encodePath(project)
|
||||
+ (remoteName != null ? "&remoteName=" + remoteName : "")
|
||||
+ "&verbose="
|
||||
+ String.valueOf(verbose);
|
||||
|
|
@ -239,7 +242,7 @@ public class GitServiceClientImpl implements GitServiceClient {
|
|||
getWsAgentBaseUrl()
|
||||
+ BRANCH
|
||||
+ "?projectPath="
|
||||
+ project
|
||||
+ encodePath(project)
|
||||
+ (listMode == null ? "" : "&listMode=" + listMode);
|
||||
return asyncRequestFactory
|
||||
.createGetRequest(url)
|
||||
|
|
@ -248,7 +251,7 @@ public class GitServiceClientImpl implements GitServiceClient {
|
|||
|
||||
@Override
|
||||
public Promise<Status> getStatus(Path project, List<String> filter) {
|
||||
StringBuilder params = new StringBuilder("?projectPath=" + project);
|
||||
StringBuilder params = new StringBuilder("?projectPath=" + encodePath(project));
|
||||
if (filter != null) {
|
||||
for (String path : filter) {
|
||||
if (!path.isEmpty()) {
|
||||
|
|
@ -271,7 +274,7 @@ public class GitServiceClientImpl implements GitServiceClient {
|
|||
getWsAgentBaseUrl()
|
||||
+ BRANCH
|
||||
+ "?projectPath="
|
||||
+ project
|
||||
+ encodePath(project)
|
||||
+ "&name="
|
||||
+ name
|
||||
+ "&force="
|
||||
|
|
@ -281,7 +284,8 @@ public class GitServiceClientImpl implements GitServiceClient {
|
|||
|
||||
@Override
|
||||
public Promise<Void> branchRename(Path project, String oldName, String newName) {
|
||||
String params = "?projectPath=" + project + "&oldName=" + oldName + "&newName=" + newName;
|
||||
String params =
|
||||
"?projectPath=" + encodePath(project) + "&oldName=" + oldName + "&newName=" + newName;
|
||||
String url = getWsAgentBaseUrl() + BRANCH + params;
|
||||
return asyncRequestFactory
|
||||
.createPostRequest(url, null)
|
||||
|
|
@ -294,7 +298,7 @@ public class GitServiceClientImpl implements GitServiceClient {
|
|||
public Promise<Branch> branchCreate(Path project, String name, String startPoint) {
|
||||
BranchCreateRequest branchCreateRequest =
|
||||
dtoFactory.createDto(BranchCreateRequest.class).withName(name).withStartPoint(startPoint);
|
||||
String url = getWsAgentBaseUrl() + BRANCH + "?projectPath=" + project;
|
||||
String url = getWsAgentBaseUrl() + BRANCH + "?projectPath=" + encodePath(project);
|
||||
return asyncRequestFactory
|
||||
.createPostRequest(url, branchCreateRequest)
|
||||
.loader(loader)
|
||||
|
|
@ -304,7 +308,7 @@ public class GitServiceClientImpl implements GitServiceClient {
|
|||
|
||||
@Override
|
||||
public Promise<String> checkout(Path project, CheckoutRequest request) {
|
||||
String url = getWsAgentBaseUrl() + CHECKOUT + "?projectPath=" + project;
|
||||
String url = getWsAgentBaseUrl() + CHECKOUT + "?projectPath=" + encodePath(project);
|
||||
return asyncRequestFactory
|
||||
.createPostRequest(url, request)
|
||||
.loader(loader)
|
||||
|
|
@ -313,7 +317,7 @@ public class GitServiceClientImpl implements GitServiceClient {
|
|||
|
||||
@Override
|
||||
public Promise<Void> remove(Path project, Path[] items, boolean cached) {
|
||||
String params = "?projectPath=" + project;
|
||||
String params = "?projectPath=" + encodePath(project);
|
||||
if (items != null) {
|
||||
for (Path item : items) {
|
||||
params += "&items=" + item.toString();
|
||||
|
|
@ -335,7 +339,7 @@ public class GitServiceClientImpl implements GitServiceClient {
|
|||
resetRequest.setFilePattern(
|
||||
stream(files).map(file -> file.isEmpty() ? "." : file.toString()).collect(toList()));
|
||||
}
|
||||
String url = getWsAgentBaseUrl() + RESET + "?projectPath=" + project;
|
||||
String url = getWsAgentBaseUrl() + RESET + "?projectPath=" + encodePath(project);
|
||||
return asyncRequestFactory.createPostRequest(url, resetRequest).loader(loader).send();
|
||||
}
|
||||
|
||||
|
|
@ -345,7 +349,7 @@ public class GitServiceClientImpl implements GitServiceClient {
|
|||
StringBuilder params =
|
||||
new StringBuilder()
|
||||
.append("?projectPath=")
|
||||
.append(project)
|
||||
.append(encodePath(project))
|
||||
.append("&skip=")
|
||||
.append(skip)
|
||||
.append("&maxCount=")
|
||||
|
|
@ -370,13 +374,13 @@ public class GitServiceClientImpl implements GitServiceClient {
|
|||
public Promise<Void> remoteAdd(Path project, String name, String url) {
|
||||
RemoteAddRequest remoteAddRequest =
|
||||
dtoFactory.createDto(RemoteAddRequest.class).withName(name).withUrl(url);
|
||||
String requestUrl = getWsAgentBaseUrl() + REMOTE + "?projectPath=" + project;
|
||||
String requestUrl = getWsAgentBaseUrl() + REMOTE + "?projectPath=" + encodePath(project);
|
||||
return asyncRequestFactory.createPutRequest(requestUrl, remoteAddRequest).loader(loader).send();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Promise<Void> remoteDelete(Path project, String name) {
|
||||
String url = getWsAgentBaseUrl() + REMOTE + '/' + name + "?projectPath=" + project;
|
||||
String url = getWsAgentBaseUrl() + REMOTE + '/' + name + "?projectPath=" + encodePath(project);
|
||||
return asyncRequestFactory.createDeleteRequest(url).loader(loader).send();
|
||||
}
|
||||
|
||||
|
|
@ -389,7 +393,7 @@ public class GitServiceClientImpl implements GitServiceClient {
|
|||
.withRefSpec(refspec)
|
||||
.withRemote(remote)
|
||||
.withRemoveDeletedRefs(removeDeletedRefs);
|
||||
String url = getWsAgentBaseUrl() + FETCH + "?projectPath=" + project;
|
||||
String url = getWsAgentBaseUrl() + FETCH + "?projectPath=" + encodePath(project);
|
||||
return asyncRequestFactory.createPostRequest(url, fetchRequest).send();
|
||||
}
|
||||
|
||||
|
|
@ -401,7 +405,7 @@ public class GitServiceClientImpl implements GitServiceClient {
|
|||
.withRemote(remote)
|
||||
.withRefSpec(refSpec)
|
||||
.withRebase(rebase);
|
||||
String url = getWsAgentBaseUrl() + PULL + "?projectPath=" + project;
|
||||
String url = getWsAgentBaseUrl() + PULL + "?projectPath=" + encodePath(project);
|
||||
return asyncRequestFactory
|
||||
.createPostRequest(url, pullRequest)
|
||||
.send(dtoUnmarshallerFactory.newUnmarshaller(PullResponse.class));
|
||||
|
|
@ -445,7 +449,7 @@ public class GitServiceClientImpl implements GitServiceClient {
|
|||
StringBuilder params =
|
||||
new StringBuilder()
|
||||
.append("?projectPath=")
|
||||
.append(project)
|
||||
.append(encodePath(project))
|
||||
.append("&noRenames=")
|
||||
.append(noRenames)
|
||||
.append("&renameLimit=")
|
||||
|
|
@ -456,7 +460,7 @@ public class GitServiceClientImpl implements GitServiceClient {
|
|||
fileFilter
|
||||
.stream()
|
||||
.filter(file -> !file.isEmpty())
|
||||
.forEach(file -> params.append("&fileFilter=").append(file));
|
||||
.forEach(file -> params.append("&fileFilter=").append(encodePath(valueOf(file))));
|
||||
}
|
||||
if (type != null) {
|
||||
params.append("&diffType=").append(type);
|
||||
|
|
@ -473,7 +477,8 @@ public class GitServiceClientImpl implements GitServiceClient {
|
|||
|
||||
@Override
|
||||
public Promise<ShowFileContentResponse> showFileContent(Path project, Path file, String version) {
|
||||
String params = "?projectPath=" + project + "&file=" + file + "&version=" + version;
|
||||
String params =
|
||||
"?projectPath=" + encodePath(project) + "&file=" + encodePath(file) + "&version=" + version;
|
||||
String url = getWsAgentBaseUrl() + SHOW + params;
|
||||
return asyncRequestFactory
|
||||
.createGetRequest(url)
|
||||
|
|
@ -484,7 +489,7 @@ public class GitServiceClientImpl implements GitServiceClient {
|
|||
@Override
|
||||
public Promise<MergeResult> merge(Path project, String commit) {
|
||||
MergeRequest mergeRequest = dtoFactory.createDto(MergeRequest.class).withCommit(commit);
|
||||
String url = getWsAgentBaseUrl() + MERGE + "?projectPath=" + project;
|
||||
String url = getWsAgentBaseUrl() + MERGE + "?projectPath=" + encodePath(project);
|
||||
return asyncRequestFactory
|
||||
.createPostRequest(url, mergeRequest)
|
||||
.loader(loader)
|
||||
|
|
@ -494,7 +499,7 @@ public class GitServiceClientImpl implements GitServiceClient {
|
|||
|
||||
@Override
|
||||
public Promise<Void> deleteRepository(Path project) {
|
||||
String url = getWsAgentBaseUrl() + REPOSITORY + "?projectPath=" + project;
|
||||
String url = getWsAgentBaseUrl() + REPOSITORY + "?projectPath=" + encodePath(project);
|
||||
return asyncRequestFactory.createDeleteRequest(url).loader(loader).send();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,10 +13,11 @@ package org.eclipse.che.ide.api.project;
|
|||
import static com.google.common.base.Strings.isNullOrEmpty;
|
||||
import static com.google.gwt.http.client.RequestBuilder.DELETE;
|
||||
import static com.google.gwt.http.client.RequestBuilder.PUT;
|
||||
import static com.google.gwt.safehtml.shared.UriUtils.encodeAllowEscapes;
|
||||
import static com.google.gwt.http.client.URL.encodePathSegment;
|
||||
import static org.eclipse.che.ide.MimeType.APPLICATION_JSON;
|
||||
import static org.eclipse.che.ide.rest.HTTPHeader.ACCEPT;
|
||||
import static org.eclipse.che.ide.rest.HTTPHeader.CONTENT_TYPE;
|
||||
import static org.eclipse.che.ide.util.PathEncoder.encodePath;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import java.util.Collections;
|
||||
|
|
@ -36,7 +37,6 @@ import org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto;
|
|||
import org.eclipse.che.api.workspace.shared.dto.SourceStorageDto;
|
||||
import org.eclipse.che.ide.MimeType;
|
||||
import org.eclipse.che.ide.api.app.AppContext;
|
||||
import org.eclipse.che.ide.api.machine.WsAgentStateController;
|
||||
import org.eclipse.che.ide.api.resources.SearchResult;
|
||||
import org.eclipse.che.ide.dto.DtoFactory;
|
||||
import org.eclipse.che.ide.resource.Path;
|
||||
|
|
@ -73,7 +73,6 @@ public class ProjectServiceClientImpl implements ProjectServiceClient {
|
|||
private static final String RESOLVE = "/resolve";
|
||||
private static final String ESTIMATE = "/estimate";
|
||||
|
||||
private final WsAgentStateController wsAgentStateController;
|
||||
private final LoaderFactory loaderFactory;
|
||||
private final AsyncRequestFactory reqFactory;
|
||||
private final DtoFactory dtoFactory;
|
||||
|
|
@ -82,13 +81,11 @@ public class ProjectServiceClientImpl implements ProjectServiceClient {
|
|||
|
||||
@Inject
|
||||
protected ProjectServiceClientImpl(
|
||||
WsAgentStateController wsAgentStateController,
|
||||
LoaderFactory loaderFactory,
|
||||
AsyncRequestFactory reqFactory,
|
||||
DtoFactory dtoFactory,
|
||||
DtoUnmarshallerFactory unmarshaller,
|
||||
AppContext appContext) {
|
||||
this.wsAgentStateController = wsAgentStateController;
|
||||
this.loaderFactory = loaderFactory;
|
||||
this.reqFactory = reqFactory;
|
||||
this.dtoFactory = dtoFactory;
|
||||
|
|
@ -110,8 +107,7 @@ public class ProjectServiceClientImpl implements ProjectServiceClient {
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public Promise<SourceEstimation> estimate(Path path, String pType) {
|
||||
final String url =
|
||||
encodeAllowEscapes(getBaseUrl() + ESTIMATE + path(path.toString()) + "?type=" + pType);
|
||||
final String url = getBaseUrl() + ESTIMATE + encodePath(path) + "?type=" + pType;
|
||||
|
||||
return reqFactory
|
||||
.createGetRequest(url)
|
||||
|
|
@ -123,7 +119,7 @@ public class ProjectServiceClientImpl implements ProjectServiceClient {
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public Promise<List<SourceEstimation>> resolveSources(Path path) {
|
||||
final String url = encodeAllowEscapes(getBaseUrl() + RESOLVE + path(path.toString()));
|
||||
final String url = getBaseUrl() + RESOLVE + encodePath(path);
|
||||
|
||||
return reqFactory
|
||||
.createGetRequest(url)
|
||||
|
|
@ -135,7 +131,7 @@ public class ProjectServiceClientImpl implements ProjectServiceClient {
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public Promise<Void> importProject(Path path, SourceStorageDto source) {
|
||||
String url = encodeAllowEscapes(getBaseUrl() + IMPORT + path(path.toString()));
|
||||
String url = getBaseUrl() + IMPORT + encodePath(path);
|
||||
|
||||
return reqFactory.createPostRequest(url, source).header(CONTENT_TYPE, APPLICATION_JSON).send();
|
||||
}
|
||||
|
|
@ -143,11 +139,8 @@ public class ProjectServiceClientImpl implements ProjectServiceClient {
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public Promise<List<SearchResult>> search(QueryExpression expression) {
|
||||
final String url =
|
||||
encodeAllowEscapes(
|
||||
getBaseUrl()
|
||||
+ SEARCH
|
||||
+ (isNullOrEmpty(expression.getPath()) ? Path.ROOT : path(expression.getPath())));
|
||||
Path prjPath = isNullOrEmpty(expression.getPath()) ? Path.ROOT : new Path(expression.getPath());
|
||||
final String url = getBaseUrl() + SEARCH + encodePath(prjPath.addLeadingSeparator());
|
||||
|
||||
StringBuilder queryParameters = new StringBuilder();
|
||||
if (expression.getName() != null && !expression.getName().isEmpty()) {
|
||||
|
|
@ -201,7 +194,7 @@ public class ProjectServiceClientImpl implements ProjectServiceClient {
|
|||
@Override
|
||||
public Promise<List<ProjectConfigDto>> createBatchProjects(
|
||||
List<NewProjectConfigDto> configurations) {
|
||||
final String url = encodeAllowEscapes(getBaseUrl() + BATCH_PROJECTS);
|
||||
final String url = getBaseUrl() + BATCH_PROJECTS;
|
||||
final String loaderMessage =
|
||||
configurations.size() > 1 ? "Creating the batch of projects..." : "Creating project...";
|
||||
return reqFactory
|
||||
|
|
@ -215,8 +208,11 @@ public class ProjectServiceClientImpl implements ProjectServiceClient {
|
|||
@Override
|
||||
public Promise<ItemReference> createFile(Path path, String content) {
|
||||
final String url =
|
||||
encodeAllowEscapes(
|
||||
getBaseUrl() + FILE + path(path.parent().toString()) + "?name=" + path.lastSegment());
|
||||
getBaseUrl()
|
||||
+ FILE
|
||||
+ encodePath(path.parent())
|
||||
+ "?name="
|
||||
+ encodePathSegment(path.lastSegment());
|
||||
|
||||
return reqFactory
|
||||
.createPostRequest(url, null)
|
||||
|
|
@ -228,7 +224,7 @@ public class ProjectServiceClientImpl implements ProjectServiceClient {
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public Promise<String> getFileContent(Path path) {
|
||||
final String url = encodeAllowEscapes(getBaseUrl() + FILE + path(path.toString()));
|
||||
final String url = getBaseUrl() + FILE + encodePath(path);
|
||||
|
||||
return reqFactory.createGetRequest(url).send(new StringUnmarshaller());
|
||||
}
|
||||
|
|
@ -236,7 +232,7 @@ public class ProjectServiceClientImpl implements ProjectServiceClient {
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public Promise<Void> setFileContent(Path path, String content) {
|
||||
final String url = encodeAllowEscapes(getBaseUrl() + FILE + path(path.toString()));
|
||||
final String url = getBaseUrl() + FILE + encodePath(path);
|
||||
|
||||
return reqFactory.createRequest(PUT, url, null, false).data(content).send();
|
||||
}
|
||||
|
|
@ -244,7 +240,7 @@ public class ProjectServiceClientImpl implements ProjectServiceClient {
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public Promise<ItemReference> createFolder(Path path) {
|
||||
final String url = encodeAllowEscapes(getBaseUrl() + FOLDER + path(path.toString()));
|
||||
final String url = getBaseUrl() + FOLDER + encodePath(path);
|
||||
|
||||
return reqFactory
|
||||
.createPostRequest(url, null)
|
||||
|
|
@ -255,20 +251,18 @@ public class ProjectServiceClientImpl implements ProjectServiceClient {
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public Promise<Void> deleteItem(Path path) {
|
||||
final String url = encodeAllowEscapes(getBaseUrl() + path(path.toString()));
|
||||
final String url = getBaseUrl() + encodePath(path);
|
||||
|
||||
return reqFactory
|
||||
.createRequest(DELETE, url, null, false)
|
||||
.loader(loaderFactory.newLoader("Deleting project..."))
|
||||
.loader(loaderFactory.newLoader("Deleting resource..."))
|
||||
.send();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public Promise<Void> copy(Path source, Path target, String newName, boolean overwrite) {
|
||||
final String url =
|
||||
encodeAllowEscapes(
|
||||
getBaseUrl() + COPY + path(source.toString()) + "?to=" + target.toString());
|
||||
final String url = getBaseUrl() + COPY + encodePath(source) + "?to=" + encodePath(target);
|
||||
|
||||
final CopyOptions copyOptions = dtoFactory.createDto(CopyOptions.class);
|
||||
copyOptions.setName(newName);
|
||||
|
|
@ -283,9 +277,7 @@ public class ProjectServiceClientImpl implements ProjectServiceClient {
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public Promise<Void> move(Path source, Path target, String newName, boolean overwrite) {
|
||||
final String url =
|
||||
encodeAllowEscapes(
|
||||
getBaseUrl() + MOVE + path(source.toString()) + "?to=" + target.toString());
|
||||
final String url = getBaseUrl() + MOVE + encodePath(source) + "?to=" + encodePath(target);
|
||||
|
||||
final MoveOptions moveOptions = dtoFactory.createDto(MoveOptions.class);
|
||||
moveOptions.setName(newName);
|
||||
|
|
@ -301,14 +293,13 @@ public class ProjectServiceClientImpl implements ProjectServiceClient {
|
|||
@Override
|
||||
public Promise<TreeElement> getTree(Path path, int depth, boolean includeFiles) {
|
||||
final String url =
|
||||
encodeAllowEscapes(
|
||||
getBaseUrl()
|
||||
+ TREE
|
||||
+ path(path.toString())
|
||||
+ "?depth="
|
||||
+ depth
|
||||
+ "&includeFiles="
|
||||
+ includeFiles);
|
||||
getBaseUrl()
|
||||
+ TREE
|
||||
+ encodePath(path.addLeadingSeparator())
|
||||
+ "?depth="
|
||||
+ depth
|
||||
+ "&includeFiles="
|
||||
+ includeFiles;
|
||||
|
||||
// temporary workaround for CHE-3467, remove loader for disable UI blocking
|
||||
// later this loader should be added with the new mechanism of client-server synchronization
|
||||
|
|
@ -322,7 +313,7 @@ public class ProjectServiceClientImpl implements ProjectServiceClient {
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public Promise<ItemReference> getItem(Path path) {
|
||||
final String url = encodeAllowEscapes(getBaseUrl() + ITEM + path(path.toString()));
|
||||
final String url = getBaseUrl() + ITEM + encodePath(path);
|
||||
|
||||
return reqFactory
|
||||
.createGetRequest(url)
|
||||
|
|
@ -334,7 +325,7 @@ public class ProjectServiceClientImpl implements ProjectServiceClient {
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public Promise<ProjectConfigDto> getProject(Path path) {
|
||||
final String url = encodeAllowEscapes(getBaseUrl() + path(path.toString()));
|
||||
final String url = getBaseUrl() + encodePath(path);
|
||||
|
||||
return reqFactory
|
||||
.createGetRequest(url)
|
||||
|
|
@ -346,7 +337,8 @@ public class ProjectServiceClientImpl implements ProjectServiceClient {
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public Promise<ProjectConfigDto> updateProject(ProjectConfigDto configuration) {
|
||||
final String url = encodeAllowEscapes(getBaseUrl() + path(configuration.getPath()));
|
||||
Path prjPath = new Path(configuration.getPath());
|
||||
final String url = getBaseUrl() + encodePath(prjPath.addLeadingSeparator());
|
||||
|
||||
return reqFactory
|
||||
.createRequest(PUT, url, configuration, false)
|
||||
|
|
@ -366,23 +358,4 @@ public class ProjectServiceClientImpl implements ProjectServiceClient {
|
|||
private String getBaseUrl() {
|
||||
return appContext.getDevMachine().getWsAgentBaseUrl() + PROJECT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes the path by adding a leading '/' if it doesn't exist. Also escapes some special
|
||||
* characters.
|
||||
*
|
||||
* <p>See following javascript functions for details: escape() will not encode: @ * / +
|
||||
* encodeURI() will not encode: ~ ! @ # $ & * ( ) = : / , ; ? + ' encodeURIComponent() will not
|
||||
* encode: ~ ! * ( ) '
|
||||
*
|
||||
* @param path path to normalize
|
||||
* @return normalized path
|
||||
*/
|
||||
private String path(String path) {
|
||||
while (path.indexOf('+') >= 0) {
|
||||
path = path.replace("+", "%2B");
|
||||
}
|
||||
|
||||
return path.startsWith("/") ? path : '/' + path;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,71 +10,367 @@
|
|||
*/
|
||||
package org.eclipse.che.ide.api.project;
|
||||
|
||||
import static com.google.gwt.http.client.RequestBuilder.DELETE;
|
||||
import static com.google.gwt.http.client.RequestBuilder.PUT;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static org.eclipse.che.ide.MimeType.APPLICATION_JSON;
|
||||
import static org.eclipse.che.ide.rest.HTTPHeader.ACCEPT;
|
||||
import static org.eclipse.che.ide.rest.HTTPHeader.CONTENT_TYPE;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.google.gwt.http.client.RequestBuilder;
|
||||
import com.google.gwtmockito.GwtMockitoTestRunner;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.eclipse.che.api.core.model.project.ProjectConfig;
|
||||
import org.eclipse.che.api.project.shared.dto.CopyOptions;
|
||||
import org.eclipse.che.api.project.shared.dto.ItemReference;
|
||||
import org.eclipse.che.api.project.shared.dto.MoveOptions;
|
||||
import org.eclipse.che.api.project.shared.dto.SearchResultDto;
|
||||
import org.eclipse.che.api.project.shared.dto.SourceEstimation;
|
||||
import org.eclipse.che.api.project.shared.dto.TreeElement;
|
||||
import org.eclipse.che.api.promises.client.Promise;
|
||||
import org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto;
|
||||
import org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto;
|
||||
import org.eclipse.che.api.workspace.shared.dto.SourceStorageDto;
|
||||
import org.eclipse.che.ide.MimeType;
|
||||
import org.eclipse.che.ide.api.app.AppContext;
|
||||
import org.eclipse.che.ide.api.machine.DevMachine;
|
||||
import org.eclipse.che.ide.api.machine.WsAgentStateController;
|
||||
import org.eclipse.che.ide.dto.DtoFactory;
|
||||
import org.eclipse.che.ide.resource.Path;
|
||||
import org.eclipse.che.ide.rest.AsyncRequest;
|
||||
import org.eclipse.che.ide.rest.AsyncRequestFactory;
|
||||
import org.eclipse.che.ide.rest.AsyncRequestLoader;
|
||||
import org.eclipse.che.ide.rest.DtoUnmarshallerFactory;
|
||||
import org.eclipse.che.ide.rest.StringUnmarshaller;
|
||||
import org.eclipse.che.ide.rest.Unmarshallable;
|
||||
import org.eclipse.che.ide.ui.loaders.request.LoaderFactory;
|
||||
import org.eclipse.che.ide.ui.loaders.request.MessageLoader;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
/**
|
||||
* Unit test for {@link ProjectServiceClientImpl}.
|
||||
*
|
||||
* @author Vlad Zhukovskyi
|
||||
* @author Oleksander Andriienko
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@RunWith(GwtMockitoTestRunner.class)
|
||||
public class ProjectServiceClientImplTest {
|
||||
|
||||
@Mock private WsAgentStateController wsAgentStateController;
|
||||
@Mock private LoaderFactory loaderFactory;
|
||||
@Mock private AsyncRequestFactory asyncRequestFactory;
|
||||
@Mock private DtoFactory dtoFactory;
|
||||
@Mock private DtoUnmarshallerFactory dtoUnmarshallerFactory;
|
||||
@Mock private AppContext appContext;
|
||||
private static final String TEXT = "to be or not to be.";
|
||||
private static final Path resourcePath =
|
||||
Path.valueOf("TestPrj/http%253A%252F%252F.org%252Fte st ");
|
||||
private static final Path targetPath = Path.valueOf("TestPrj/target here* ");
|
||||
|
||||
private ProjectServiceClientImpl projectServiceClient;
|
||||
@Mock private LoaderFactory loaderFactory;
|
||||
@Mock private AsyncRequestFactory requestFactory;
|
||||
@Mock private DtoFactory dtoFactory;
|
||||
@Mock private DtoUnmarshallerFactory unmarshaller;
|
||||
@Mock private AppContext appContext;
|
||||
@Mock private AsyncRequest asyncRequest;
|
||||
|
||||
@Mock private Unmarshallable<ItemReference> unmarshallableItemRef;
|
||||
@Mock private Unmarshallable<List<ProjectConfigDto>> unmarshallablePrjsConf;
|
||||
@Mock private Unmarshallable<ProjectConfigDto> unmarshallablePrjConf;
|
||||
@Mock private Unmarshallable<List<SearchResultDto>> unmarshallableSearch;
|
||||
@Mock private Promise<List<SearchResultDto>> searchPromise;
|
||||
@Mock private Unmarshallable<List<SourceEstimation>> unmarshallbleSourcesEstimation;
|
||||
@Mock private Unmarshallable<SourceEstimation> unmarshallbleSourceEstimation;
|
||||
@Mock private Unmarshallable<TreeElement> unmarshallableTreeElem;
|
||||
|
||||
@Mock private Promise<ItemReference> itemRefPromise;
|
||||
@Mock private MessageLoader messageLoader;
|
||||
|
||||
@Mock private NewProjectConfigDto prjConfig1;
|
||||
@Mock private NewProjectConfigDto prjConfig2;
|
||||
@Mock private SourceStorageDto source;
|
||||
|
||||
@Captor private ArgumentCaptor<List<NewProjectConfigDto>> prjsArgCaptor;
|
||||
|
||||
private ProjectServiceClientImpl client;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
projectServiceClient =
|
||||
client =
|
||||
new ProjectServiceClientImpl(
|
||||
wsAgentStateController,
|
||||
loaderFactory,
|
||||
asyncRequestFactory,
|
||||
dtoFactory,
|
||||
dtoUnmarshallerFactory,
|
||||
appContext);
|
||||
loaderFactory, requestFactory, dtoFactory, unmarshaller, appContext);
|
||||
DevMachine devMachine = mock(DevMachine.class);
|
||||
when(devMachine.getWsAgentBaseUrl()).thenReturn("");
|
||||
when(devMachine.getWsAgentBaseUrl()).thenReturn("http://127.0.0.3/api");
|
||||
|
||||
when(appContext.getDevMachine()).thenReturn(devMachine);
|
||||
when(loaderFactory.newLoader(any())).thenReturn(messageLoader);
|
||||
when(asyncRequest.loader(messageLoader)).thenReturn(asyncRequest);
|
||||
when(asyncRequest.data(any())).thenReturn(asyncRequest);
|
||||
when(asyncRequest.send(unmarshallableItemRef)).thenReturn(itemRefPromise);
|
||||
when(asyncRequest.header(any(), any())).thenReturn(asyncRequest);
|
||||
when(unmarshaller.newUnmarshaller(ItemReference.class)).thenReturn(unmarshallableItemRef);
|
||||
when(unmarshaller.newListUnmarshaller(ProjectConfigDto.class))
|
||||
.thenReturn(unmarshallablePrjsConf);
|
||||
when(unmarshaller.newListUnmarshaller(SourceEstimation.class))
|
||||
.thenReturn(unmarshallbleSourcesEstimation);
|
||||
when(unmarshaller.newUnmarshaller(SourceEstimation.class))
|
||||
.thenReturn(unmarshallbleSourceEstimation);
|
||||
when(unmarshaller.newListUnmarshaller(SearchResultDto.class)).thenReturn(unmarshallableSearch);
|
||||
when(unmarshaller.newUnmarshaller(TreeElement.class)).thenReturn(unmarshallableTreeElem);
|
||||
when(unmarshaller.newUnmarshaller(ProjectConfigDto.class)).thenReturn(unmarshallablePrjConf);
|
||||
|
||||
when(requestFactory.createGetRequest(anyString())).thenReturn(asyncRequest);
|
||||
when(requestFactory.createPostRequest(anyString(), any(MimeType.class)))
|
||||
.thenReturn(asyncRequest);
|
||||
when(requestFactory.createRequest(
|
||||
any(RequestBuilder.Method.class), anyString(), any(), anyBoolean()))
|
||||
.thenReturn(asyncRequest);
|
||||
when(requestFactory.createPostRequest(anyString(), any())).thenReturn(asyncRequest);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldNotSetupLoaderForTheGetTreeMethod() throws Exception {
|
||||
AsyncRequest asyncRequest = mock(AsyncRequest.class);
|
||||
|
||||
when(asyncRequestFactory.createGetRequest(anyString())).thenReturn(asyncRequest);
|
||||
when(asyncRequest.header(anyString(), anyString())).thenReturn(asyncRequest);
|
||||
|
||||
projectServiceClient.getTree(Path.EMPTY, 1, true);
|
||||
client.getTree(Path.EMPTY, 1, true);
|
||||
|
||||
verify(asyncRequest, never()).loader(any(AsyncRequestLoader.class)); //see CHE-3467
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnListProjects() {
|
||||
client.getProjects();
|
||||
|
||||
verify(requestFactory).createGetRequest(any());
|
||||
verify(asyncRequest).header(ACCEPT, MimeType.APPLICATION_JSON);
|
||||
verify(unmarshaller).newListUnmarshaller(ProjectConfigDto.class);
|
||||
verify(asyncRequest).send(unmarshallablePrjsConf);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldEncodeUrlAndEstimateProject() {
|
||||
String prjType = "java";
|
||||
|
||||
client.estimate(resourcePath, prjType);
|
||||
|
||||
verify(requestFactory).createGetRequest(any());
|
||||
verify(asyncRequest).header(ACCEPT, MimeType.APPLICATION_JSON);
|
||||
verify(loaderFactory).newLoader("Estimating project...");
|
||||
verify(asyncRequest).loader(messageLoader);
|
||||
verify(asyncRequest).send(unmarshallbleSourceEstimation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldEncodeUrlAndResolveProjectSources() {
|
||||
client.resolveSources(resourcePath);
|
||||
|
||||
verify(requestFactory).createGetRequest(any());
|
||||
verify(asyncRequest).header(ACCEPT, MimeType.APPLICATION_JSON);
|
||||
verify(loaderFactory).newLoader("Resolving sources...");
|
||||
verify(asyncRequest).loader(messageLoader);
|
||||
verify(unmarshaller).newListUnmarshaller(SourceEstimation.class);
|
||||
verify(asyncRequest).send(unmarshallbleSourcesEstimation);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldEncodeUrlAndImportProject() {
|
||||
client.importProject(resourcePath, source);
|
||||
|
||||
verify(requestFactory).createPostRequest(any(), eq(source));
|
||||
verify(asyncRequest).header(CONTENT_TYPE, APPLICATION_JSON);
|
||||
verify(asyncRequest).send();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldEncodeUrlAndSearchResourceReferences() {
|
||||
QueryExpression expression = new QueryExpression();
|
||||
expression.setName(TEXT);
|
||||
expression.setText(TEXT);
|
||||
expression.setPath(resourcePath.toString());
|
||||
expression.setMaxItems(100);
|
||||
expression.setSkipCount(10);
|
||||
when(asyncRequest.send(unmarshallableSearch)).thenReturn(searchPromise);
|
||||
|
||||
client.search(expression);
|
||||
|
||||
verify(requestFactory).createGetRequest(any());
|
||||
verify(asyncRequest).header(ACCEPT, MimeType.APPLICATION_JSON);
|
||||
verify(loaderFactory).newLoader("Searching...");
|
||||
verify(asyncRequest).loader(messageLoader);
|
||||
verify(unmarshaller).newListUnmarshaller(SearchResultDto.class);
|
||||
verify(asyncRequest).send(unmarshallableSearch);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateOneProjectByBatch() {
|
||||
List<NewProjectConfigDto> configs = singletonList(prjConfig1);
|
||||
|
||||
client.createBatchProjects(configs);
|
||||
|
||||
verify(requestFactory).createPostRequest(anyString(), prjsArgCaptor.capture());
|
||||
verify(asyncRequest).header(ACCEPT, MimeType.APPLICATION_JSON);
|
||||
verify(loaderFactory).newLoader("Creating project...");
|
||||
verify(asyncRequest).loader(messageLoader);
|
||||
verify(asyncRequest).send(unmarshallablePrjsConf);
|
||||
verify(unmarshaller).newListUnmarshaller(ProjectConfigDto.class);
|
||||
|
||||
assertEquals(1, prjsArgCaptor.getValue().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateFewProjectByBatch() {
|
||||
List<NewProjectConfigDto> configs = Arrays.asList(prjConfig1, prjConfig2);
|
||||
|
||||
client.createBatchProjects(configs);
|
||||
|
||||
verify(requestFactory).createPostRequest(anyString(), prjsArgCaptor.capture());
|
||||
verify(asyncRequest).header(ACCEPT, MimeType.APPLICATION_JSON);
|
||||
verify(loaderFactory).newLoader("Creating the batch of projects...");
|
||||
verify(asyncRequest).loader(messageLoader);
|
||||
verify(asyncRequest).send(unmarshallablePrjsConf);
|
||||
verify(unmarshaller).newListUnmarshaller(ProjectConfigDto.class);
|
||||
|
||||
assertEquals(2, prjsArgCaptor.getValue().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldEncodeUrlAndCreateFile() {
|
||||
client.createFile(resourcePath, TEXT);
|
||||
|
||||
verify(requestFactory).createPostRequest(any(), any());
|
||||
verify(asyncRequest).data(TEXT);
|
||||
verify(loaderFactory).newLoader("Creating file...");
|
||||
verify(asyncRequest).loader(messageLoader);
|
||||
verify(asyncRequest).send(unmarshallableItemRef);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldEncodeUrlAndGetFileContent() {
|
||||
client.getFileContent(resourcePath);
|
||||
|
||||
verify(requestFactory).createGetRequest(any());
|
||||
verify(asyncRequest).send(any(StringUnmarshaller.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldEncodeUrlAndSetFileContent() {
|
||||
client.setFileContent(resourcePath, TEXT);
|
||||
|
||||
verify(requestFactory).createRequest(eq(PUT), any(), any(), eq(false));
|
||||
verify(asyncRequest).data(TEXT);
|
||||
verify(asyncRequest).send();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldEncodeUrlAndCreateFolder() {
|
||||
client.createFolder(resourcePath);
|
||||
|
||||
verify(requestFactory).createPostRequest(any(), any());
|
||||
verify(loaderFactory).newLoader("Creating folder...");
|
||||
verify(asyncRequest).loader(messageLoader);
|
||||
verify(unmarshaller).newUnmarshaller(ItemReference.class);
|
||||
verify(asyncRequest).send(unmarshallableItemRef);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldEncodeUrlAndDeleteFolder() {
|
||||
client.deleteItem(resourcePath);
|
||||
|
||||
verify(requestFactory).createRequest(eq(DELETE), any(), any(), eq(false));
|
||||
verify(loaderFactory).newLoader("Deleting resource...");
|
||||
verify(asyncRequest).loader(messageLoader);
|
||||
verify(asyncRequest).send();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldEncodeUrlAndCopyResource() {
|
||||
CopyOptions copyOptions = mock(CopyOptions.class);
|
||||
when(dtoFactory.createDto(CopyOptions.class)).thenReturn(copyOptions);
|
||||
|
||||
client.copy(resourcePath, targetPath, TEXT, true);
|
||||
|
||||
verify(dtoFactory).createDto(CopyOptions.class);
|
||||
verify(copyOptions).setName(any());
|
||||
verify(copyOptions).setOverWrite(true);
|
||||
|
||||
verify(requestFactory).createPostRequest(any(), eq(copyOptions));
|
||||
verify(loaderFactory).newLoader("Copying...");
|
||||
verify(asyncRequest).loader(messageLoader);
|
||||
verify(asyncRequest).send();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldEncodeUrlAndMoveResource() {
|
||||
MoveOptions moveOptions = mock(MoveOptions.class);
|
||||
when(dtoFactory.createDto(MoveOptions.class)).thenReturn(moveOptions);
|
||||
|
||||
client.move(resourcePath, targetPath, TEXT, true);
|
||||
|
||||
verify(dtoFactory).createDto(MoveOptions.class);
|
||||
verify(moveOptions).setName(any());
|
||||
verify(moveOptions).setOverWrite(true);
|
||||
verify(requestFactory).createPostRequest(any(), eq(moveOptions));
|
||||
verify(loaderFactory).newLoader("Moving...");
|
||||
verify(asyncRequest).loader(messageLoader);
|
||||
verify(asyncRequest).send();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldEncodeUrlAndGetTree() {
|
||||
client.getTree(resourcePath, 2, true);
|
||||
|
||||
verify(requestFactory).createGetRequest(any());
|
||||
verify(asyncRequest).header(ACCEPT, MimeType.APPLICATION_JSON);
|
||||
verify(unmarshaller).newUnmarshaller(TreeElement.class);
|
||||
verify(asyncRequest).send(unmarshallableTreeElem);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldEncodeUrlAndGetItem() {
|
||||
client.getItem(resourcePath);
|
||||
|
||||
verify(requestFactory).createGetRequest(any());
|
||||
verify(asyncRequest).header(ACCEPT, MimeType.APPLICATION_JSON);
|
||||
verify(loaderFactory).newLoader("Getting item...");
|
||||
verify(unmarshaller).newUnmarshaller(ItemReference.class);
|
||||
verify(asyncRequest).send(unmarshallableItemRef);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldEncodeUrlAndGetProject() {
|
||||
client.getProject(Path.valueOf(TEXT));
|
||||
|
||||
verify(requestFactory).createGetRequest(any());
|
||||
verify(asyncRequest).header(ACCEPT, MimeType.APPLICATION_JSON);
|
||||
verify(loaderFactory).newLoader("Getting project...");
|
||||
verify(asyncRequest).loader(messageLoader);
|
||||
verify(unmarshaller).newUnmarshaller(ProjectConfigDto.class);
|
||||
verify(asyncRequest).send(unmarshallablePrjConf);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldEncodeUrlAndUpdateProject() {
|
||||
when(requestFactory.createRequest(
|
||||
any(RequestBuilder.Method.class), anyString(), any(ProjectConfig.class), anyBoolean()))
|
||||
.thenReturn(asyncRequest);
|
||||
when(prjConfig1.getPath()).thenReturn(TEXT);
|
||||
|
||||
client.updateProject(prjConfig1);
|
||||
|
||||
verify(requestFactory).createRequest(eq(PUT), anyString(), eq(prjConfig1), eq(false));
|
||||
verify(asyncRequest).header(CONTENT_TYPE, MimeType.APPLICATION_JSON);
|
||||
verify(asyncRequest).header(ACCEPT, MimeType.APPLICATION_JSON);
|
||||
verify(loaderFactory).newLoader("Updating project...");
|
||||
verify(asyncRequest).loader(messageLoader);
|
||||
verify(unmarshaller).newUnmarshaller(ProjectConfigDto.class);
|
||||
verify(asyncRequest).send(unmarshallablePrjConf);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -186,6 +186,24 @@ public final class Path {
|
|||
return new Path(device, segments, separators | HAS_TRAILING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a path with the same segments as this path but with a leading separator added.
|
||||
*
|
||||
* <p>If this path already has a leading separator, this path is returned.
|
||||
*
|
||||
* @return the new path
|
||||
* @see #hasTrailingSeparator()
|
||||
*/
|
||||
public Path addLeadingSeparator() {
|
||||
if (hasLeadingSeparator() || isRoot()) {
|
||||
return this;
|
||||
}
|
||||
if (isEmpty()) {
|
||||
return new Path(device, segments, HAS_LEADING);
|
||||
}
|
||||
return new Path(device, segments, separators | HAS_LEADING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the canonicalized path obtained from the concatenation of the given path's segments to
|
||||
* the end of this path. If the given path has a trailing separator, the result will have a
|
||||
|
|
@ -536,6 +554,20 @@ public final class Path {
|
|||
return (separators & HAS_TRAILING) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this path has a leading separator.
|
||||
*
|
||||
* <p>Note: In the root path ("/"), the separator is considered to be leading rather than
|
||||
* trailing.
|
||||
*
|
||||
* @return <code>true</code> if this path has a leading separator, and <code>false</code>
|
||||
* otherwise
|
||||
* @see #addLeadingSeparator()
|
||||
*/
|
||||
public boolean hasLeadingSeparator() {
|
||||
return (separators & HAS_LEADING) != 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the current path with the given string.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2012-2017 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.util;
|
||||
|
||||
import static com.google.gwt.http.client.URL.encodePathSegment;
|
||||
import static org.eclipse.che.ide.resource.Path.SEPARATOR;
|
||||
|
||||
import org.eclipse.che.ide.resource.Path;
|
||||
|
||||
/**
|
||||
* @author Alexander Andrienko
|
||||
* @author Mykola Morhun
|
||||
*/
|
||||
public class PathEncoder {
|
||||
|
||||
private PathEncoder() {}
|
||||
|
||||
/** Returns path encoded by segments without device. */
|
||||
public static String encodePath(Path path) {
|
||||
StringBuilder encodedPath = new StringBuilder();
|
||||
|
||||
if (path.hasLeadingSeparator()) {
|
||||
encodedPath.append(SEPARATOR);
|
||||
}
|
||||
|
||||
String segment;
|
||||
for (int i = 0; i < path.segmentCount(); i++) {
|
||||
segment = path.segment(i);
|
||||
encodedPath.append(encodePathSegment(segment));
|
||||
encodedPath.append(SEPARATOR);
|
||||
}
|
||||
|
||||
if (!path.isEmpty() && !path.isRoot() && !path.hasTrailingSeparator()) {
|
||||
encodedPath.deleteCharAt(encodedPath.length() - 1);
|
||||
}
|
||||
|
||||
return encodedPath.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@ package org.eclipse.che.ide.resource;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
|
@ -327,4 +328,72 @@ public class PathTest {
|
|||
|
||||
assertEquals(result, common);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldCheckExistenceOfLeadingSeparator() {
|
||||
assertTrue(Path.valueOf("/foo").hasLeadingSeparator());
|
||||
assertFalse(Path.valueOf("foo").hasLeadingSeparator());
|
||||
assertTrue(Path.valueOf("/").hasLeadingSeparator());
|
||||
assertFalse(Path.valueOf("").hasLeadingSeparator());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnNewPathWithAddedLeadingSeparatorIfPathHasNotIt() {
|
||||
final Path path = Path.valueOf("Test/src/main/java");
|
||||
|
||||
final Path pathWithSeparator = path.addLeadingSeparator();
|
||||
|
||||
assertNotEquals(path, pathWithSeparator);
|
||||
|
||||
assertFalse(path.hasLeadingSeparator());
|
||||
assertTrue(pathWithSeparator.hasLeadingSeparator());
|
||||
|
||||
assertTrue(path.toString().equals("Test/src/main/java"));
|
||||
assertTrue(pathWithSeparator.toString().equals("/Test/src/main/java"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnTheSamePathIfPathAlreadyHasLeadingSeparator() {
|
||||
final Path path = Path.valueOf("/Test/src/main/java");
|
||||
|
||||
final Path pathWithSeparator = path.addLeadingSeparator();
|
||||
|
||||
assertEquals(path, pathWithSeparator);
|
||||
|
||||
assertTrue(path.hasLeadingSeparator());
|
||||
assertTrue(pathWithSeparator.hasLeadingSeparator());
|
||||
|
||||
assertTrue(path.toString().equals("/Test/src/main/java"));
|
||||
assertTrue(pathWithSeparator.toString().equals("/Test/src/main/java"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnTheSamePathIfPathIsRoot() {
|
||||
final Path path = Path.valueOf("/");
|
||||
|
||||
final Path pathWithSeparator = path.addLeadingSeparator();
|
||||
|
||||
assertEquals(path, pathWithSeparator);
|
||||
|
||||
assertTrue(path.hasLeadingSeparator());
|
||||
assertTrue(pathWithSeparator.hasLeadingSeparator());
|
||||
|
||||
assertTrue(path.toString().equals("/"));
|
||||
assertTrue(pathWithSeparator.toString().equals("/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnNewRootPathIfPathIsEmpty() {
|
||||
final Path path = Path.valueOf("");
|
||||
|
||||
final Path pathWithSeparator = path.addLeadingSeparator();
|
||||
|
||||
assertNotEquals(path, pathWithSeparator);
|
||||
|
||||
assertFalse(path.hasLeadingSeparator());
|
||||
assertTrue(pathWithSeparator.hasLeadingSeparator());
|
||||
|
||||
assertTrue(path.toString().equals(""));
|
||||
assertTrue(pathWithSeparator.toString().equals("/"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@ package org.eclipse.che.ide.ext.java.client.dependenciesupdater;
|
|||
|
||||
import static com.google.gwt.http.client.RequestBuilder.GET;
|
||||
import static org.eclipse.che.ide.MimeType.APPLICATION_JSON;
|
||||
import static org.eclipse.che.ide.resource.Path.valueOf;
|
||||
import static org.eclipse.che.ide.rest.HTTPHeader.ACCEPT;
|
||||
import static org.eclipse.che.ide.util.PathEncoder.encodePath;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
|
@ -48,7 +50,8 @@ public class JavaClasspathServiceClientImpl implements JavaClasspathServiceClien
|
|||
@Override
|
||||
public void updateDependencies(
|
||||
String projectPath, RequestCallback<ClassPathBuilderResult> callback) {
|
||||
final String requestUrl = baseHttpUrl + "/classpath/update?projectpath=" + projectPath;
|
||||
final String requestUrl =
|
||||
baseHttpUrl + "/classpath/update?projectpath=" + encodePath(valueOf(projectPath));
|
||||
|
||||
MessageBuilder builder = new MessageBuilder(GET, requestUrl);
|
||||
builder.header(ACCEPT, APPLICATION_JSON);
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@
|
|||
*/
|
||||
package org.eclipse.che.ide.ext.java.client.project.classpath.service;
|
||||
|
||||
import static org.eclipse.che.ide.resource.Path.valueOf;
|
||||
import static org.eclipse.che.ide.util.PathEncoder.encodePath;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import java.util.List;
|
||||
|
|
@ -55,7 +58,7 @@ public class ClasspathServiceClientImpl implements ClasspathServiceClient {
|
|||
appContext.getDevMachine().getWsAgentBaseUrl()
|
||||
+ pathToService
|
||||
+ "?projectpath="
|
||||
+ projectPath;
|
||||
+ encodePath(valueOf(projectPath));
|
||||
|
||||
return asyncRequestFactory
|
||||
.createGetRequest(url)
|
||||
|
|
|
|||
|
|
@ -12,8 +12,10 @@ package org.eclipse.che.ide.ext.java.client.refactoring.service;
|
|||
|
||||
import static org.eclipse.che.ide.MimeType.APPLICATION_JSON;
|
||||
import static org.eclipse.che.ide.MimeType.TEXT_PLAIN;
|
||||
import static org.eclipse.che.ide.resource.Path.valueOf;
|
||||
import static org.eclipse.che.ide.rest.HTTPHeader.ACCEPT;
|
||||
import static org.eclipse.che.ide.rest.HTTPHeader.CONTENT_TYPE;
|
||||
import static org.eclipse.che.ide.util.PathEncoder.encodePath;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
|
@ -240,7 +242,7 @@ final class RefactoringServiceClientImpl implements RefactoringServiceClient {
|
|||
appContext.getDevMachine().getWsAgentBaseUrl()
|
||||
+ pathToService
|
||||
+ "reindex?projectpath="
|
||||
+ projectPath;
|
||||
+ encodePath(valueOf(projectPath));
|
||||
|
||||
return asyncRequestFactory.createGetRequest(url).loader(loader).send();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@
|
|||
*/
|
||||
package org.eclipse.che.plugin.java.plain.client.service;
|
||||
|
||||
import static org.eclipse.che.ide.resource.Path.valueOf;
|
||||
import static org.eclipse.che.ide.util.PathEncoder.encodePath;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import java.util.List;
|
||||
|
|
@ -49,7 +52,7 @@ public class ClasspathUpdaterServiceClientImpl implements ClasspathUpdaterServic
|
|||
appContext.getDevMachine().getWsAgentBaseUrl()
|
||||
+ pathToService
|
||||
+ "update?projectpath="
|
||||
+ projectPath;
|
||||
+ encodePath(valueOf(projectPath));
|
||||
return asyncRequestFactory.createPostRequest(url, entries).loader(loader).send();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import org.eclipse.che.api.promises.client.js.Promises;
|
|||
import org.eclipse.lsp4j.SymbolInformation;
|
||||
import org.eclipse.lsp4j.TextEdit;
|
||||
import org.eclipse.lsp4j.WorkspaceSymbolParams;
|
||||
import org.eclipse.lsp4j.services.WorkspaceService;
|
||||
|
||||
/** @author Evgen Vidolob */
|
||||
@Singleton
|
||||
|
|
@ -34,8 +35,7 @@ public class WorkspaceServiceClient {
|
|||
}
|
||||
|
||||
/**
|
||||
* GWT client implementation of {@link
|
||||
* io.typefox.lsapi.WorkspaceService#symbol(io.typefox.lsapi.WorkspaceSymbolParams)}
|
||||
* GWT client implementation of {@link WorkspaceService#symbol(WorkspaceSymbolParams)}
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@
|
|||
*/
|
||||
package org.eclipse.che.plugin.maven.client.service;
|
||||
|
||||
import static org.eclipse.che.ide.resource.Path.valueOf;
|
||||
import static org.eclipse.che.ide.util.PathEncoder.encodePath;
|
||||
|
||||
import com.google.gwt.http.client.Response;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
|
@ -50,7 +53,7 @@ public class MavenServerServiceClientImpl implements MavenServerServiceClient {
|
|||
appContext.getDevMachine().getWsAgentBaseUrl()
|
||||
+ servicePath
|
||||
+ "effective/pom?projectpath="
|
||||
+ projectPath;
|
||||
+ encodePath(valueOf(projectPath));
|
||||
|
||||
return asyncRequestFactory
|
||||
.createGetRequest(url)
|
||||
|
|
@ -64,7 +67,7 @@ public class MavenServerServiceClientImpl implements MavenServerServiceClient {
|
|||
appContext.getDevMachine().getWsAgentBaseUrl()
|
||||
+ servicePath
|
||||
+ "download/sources?projectpath="
|
||||
+ projectPath
|
||||
+ encodePath(valueOf(projectPath))
|
||||
+ "&fqn="
|
||||
+ fqn;
|
||||
return asyncRequestFactory
|
||||
|
|
@ -90,7 +93,7 @@ public class MavenServerServiceClientImpl implements MavenServerServiceClient {
|
|||
public Promise<Void> reImportProjects(@NotNull List<String> projectsPaths) {
|
||||
StringBuilder queryParameters = new StringBuilder();
|
||||
for (String path : projectsPaths) {
|
||||
queryParameters.append("&projectPath=").append(path);
|
||||
queryParameters.append("&projectPath=").append(encodePath(valueOf(path)));
|
||||
}
|
||||
final String url =
|
||||
appContext.getDevMachine().getWsAgentBaseUrl()
|
||||
|
|
@ -107,7 +110,7 @@ public class MavenServerServiceClientImpl implements MavenServerServiceClient {
|
|||
appContext.getDevMachine().getWsAgentBaseUrl()
|
||||
+ servicePath
|
||||
+ "pom/reconcile?pompath="
|
||||
+ pomPath;
|
||||
+ encodePath(valueOf(pomPath));
|
||||
return asyncRequestFactory.createGetRequest(url).send();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue