Skip to content

Commit

Permalink
IDEX-2721 Verify revision exists before to SVN Export
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Tournié <stephane.tournie@serli.com>
  • Loading branch information
Stéphane Tournié committed Apr 7, 2016
1 parent f54229e commit 83d6cec
Show file tree
Hide file tree
Showing 22 changed files with 382 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.google.gwt.user.client.rpc.AsyncCallback;

import org.eclipse.che.plugin.svn.shared.Depth;
import org.eclipse.che.plugin.svn.shared.GetRevisionsResponse;
import org.eclipse.che.plugin.svn.shared.InfoResponse;
import org.eclipse.che.plugin.svn.shared.ListResponse;
import org.eclipse.che.ide.rest.AsyncRequestCallback;
Expand Down Expand Up @@ -328,7 +329,6 @@ void propertyGet(final String projectPath,
* Get properties set for a path or a target.
*
* @param projectPath the project path
* @param propertyName the property name
* @param path path to which property get
* @param callback the callback
*/
Expand All @@ -354,4 +354,19 @@ void propertyList(final String projectPath,
*/
void propertyDelete(final String projectPath, final String propertyName, final Depth depth,
final boolean force, final String path, final AsyncRequestCallback<CLIOutputResponse> callback);

/**
* Get the list of all revisions where a given path was modified
*
* @param projectPath
* the project path
* @param path
* path to get the revisions for
* @param revisionRange
* the range of revisions to check
* @param callback
* the callback
*/
void getRevisions(final @NotNull String projectPath, final String path, final String revisionRange,
final AsyncRequestCallback<GetRevisionsResponse> callback);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.eclipse.che.plugin.svn.shared.CommitRequest;
import org.eclipse.che.plugin.svn.shared.CopyRequest;
import org.eclipse.che.plugin.svn.shared.Depth;
import org.eclipse.che.plugin.svn.shared.GetRevisionsRequest;
import org.eclipse.che.plugin.svn.shared.GetRevisionsResponse;
import org.eclipse.che.plugin.svn.shared.InfoRequest;
import org.eclipse.che.plugin.svn.shared.InfoResponse;
import org.eclipse.che.plugin.svn.shared.ListRequest;
Expand Down Expand Up @@ -411,6 +413,27 @@ public void propertyDelete(String projectPath, String propertyName, Depth depth,
asyncRequestFactory.createPostRequest(baseHttpUrl + "/propdel", request).loader(loader).send(callback);
}

/**
* Get the list of all revisions where a given path was modified
*
* @param projectPath
* the project path
* @param path
* path to get the revisions for
* @param revisionRange
* the range of revisions to check
* @param callback
*/
@Override
public void getRevisions(@NotNull String projectPath, String path, String revisionRange,
AsyncRequestCallback<GetRevisionsResponse> callback) {
final GetRevisionsRequest request = dtoFactory.createDto(GetRevisionsRequest.class)
.withProjectPath(projectPath)
.withPath(path)
.withRevisionRange(revisionRange);
asyncRequestFactory.createPostRequest(baseHttpUrl + "/revisions", request).loader(loader).send(callback);
}

@Override
public void propertyGet(String projectPath, String propertyName, String path, AsyncRequestCallback<CLIOutputResponse> callback) {
final PropertyRequest request = dtoFactory.createDto(PropertyGetRequest.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,18 @@ public interface SubversionExtensionLocalizationConstants extends Messages {
@Key("export.successful")
String exportSuccessful(String path);

@Key("export.fail.noprojectpath")
String exportFailedNoProjectPath();

@Key("export.fail.command.execution")
String exportCommandExecutionError();

@Key("export.fail.revision.donotexist")
String exportRevisionDoNotExistForPath(String givenRevision, String path);

@Key("export.fail.norevision")
String exportNoRevisionForPath(String path);

/* Move dialog */
@Key("move.fail.to.get.project")
String moveFailToGetProject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.google.inject.Inject;
import com.google.inject.Singleton;

import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.plugin.svn.ide.SubversionExtensionLocalizationConstants;
import org.eclipse.che.plugin.svn.ide.SubversionExtensionResources;
Expand All @@ -33,4 +34,8 @@ public ApplyPatchAction(final AppContext appContext,
appContext, constants, resources, projectExplorerPresenter);
}

@Override
public void actionPerformed(ActionEvent actionEvent) {

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

import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.plugin.svn.ide.SubversionExtensionLocalizationConstants;
import org.eclipse.che.plugin.svn.ide.SubversionExtensionResources;
Expand All @@ -33,4 +34,8 @@ public BranchTagAction(final AppContext appContext,
appContext, constants, resources, projectExplorerPresenter);
}

@Override
public void actionPerformed(ActionEvent actionEvent) {

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

import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.plugin.svn.ide.SubversionExtensionLocalizationConstants;
import org.eclipse.che.plugin.svn.ide.SubversionExtensionResources;
Expand All @@ -33,4 +34,8 @@ public CreatePatchAction(final AppContext appContext,
projectExplorerPresenter);
}

@Override
public void actionPerformed(ActionEvent actionEvent) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,4 @@ public LogAction(final ShowLogPresenter presenter,
public void actionPerformed(final ActionEvent e) {
presenter.showLog();
}

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

import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.plugin.svn.ide.SubversionExtensionLocalizationConstants;
import org.eclipse.che.plugin.svn.ide.SubversionExtensionResources;
Expand All @@ -33,4 +34,8 @@ public RelocateAction(final AppContext appContext,
appContext, constants, resources, projectExplorerPresenter);
}

@Override
public void actionPerformed(ActionEvent actionEvent) {

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

import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.plugin.svn.ide.SubversionExtensionLocalizationConstants;
import org.eclipse.che.plugin.svn.ide.SubversionExtensionResources;
Expand All @@ -33,4 +34,8 @@ public RenameAction(final AppContext appContext,
constants, resources, projectExplorerPresenter);
}

@Override
public void actionPerformed(ActionEvent actionEvent) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ public void updateProjectAction(ActionEvent e) {
}

@Override
public void actionPerformed(ActionEvent actionEvent) {
//Window.alert(constants.actionNotImplemented());
}
public abstract void actionPerformed(ActionEvent actionEvent);

/**
* @return the active project or null if there is none
Expand All @@ -79,9 +77,7 @@ protected CurrentProject getActiveProject() {
*/
protected boolean isItemSelected() {
final Selection<?> selection = projectExplorerPresenter.getSelection();

return selection != null && selection.getHeadElement() != null &&
selection.getHeadElement() instanceof HasStorablePath;
return !selection.isEmpty();
}

/**
Expand Down Expand Up @@ -110,5 +106,4 @@ protected boolean isSubversionWC() {
protected boolean isSelectionRequired() {
return false;
}

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

import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.plugin.svn.ide.SubversionExtensionLocalizationConstants;
import org.eclipse.che.plugin.svn.ide.SubversionExtensionResources;
Expand All @@ -33,4 +34,8 @@ public SwitchAction(final AppContext appContext,
appContext, constants, resources, projectExplorerPresenter);
}

@Override
public void actionPerformed(ActionEvent actionEvent) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,32 @@
*******************************************************************************/
package org.eclipse.che.plugin.svn.ide.export;

import com.google.common.base.Strings;
import com.google.gwt.user.client.Window;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.google.inject.name.Named;
import com.google.web.bindery.event.shared.EventBus;

import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.notification.NotificationManager;
import org.eclipse.che.ide.api.parts.WorkspaceAgent;
import org.eclipse.che.ide.api.notification.StatusNotification;
import org.eclipse.che.ide.api.project.node.HasStorablePath;
import org.eclipse.che.ide.extension.machine.client.processes.ConsolesPanelPresenter;
import org.eclipse.che.ide.part.explorer.project.ProjectExplorerPresenter;
import org.eclipse.che.ide.rest.AsyncRequestCallback;
import org.eclipse.che.ide.rest.DtoUnmarshallerFactory;
import org.eclipse.che.plugin.svn.ide.SubversionClientService;
import org.eclipse.che.plugin.svn.ide.SubversionExtensionLocalizationConstants;
import org.eclipse.che.plugin.svn.ide.common.SubversionActionPresenter;
import org.eclipse.che.plugin.svn.ide.common.SubversionOutputConsoleFactory;
import org.eclipse.che.plugin.svn.ide.common.SubversionOutputConsolePresenter;
import org.eclipse.che.plugin.svn.shared.GetRevisionsResponse;

import java.util.List;

import static com.google.common.base.Strings.emptyToNull;
import static com.google.common.base.Strings.isNullOrEmpty;
import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL;
import static org.eclipse.che.ide.api.notification.StatusNotification.Status.PROGRESS;
import static org.eclipse.che.ide.api.notification.StatusNotification.Status.SUCCESS;

/**
* Presenter for the {@link ExportView}.
Expand All @@ -37,6 +46,8 @@
public class ExportPresenter extends SubversionActionPresenter implements ExportView.ActionDelegate {

private ExportView view;
private final DtoUnmarshallerFactory dtoUnmarshallerFactory;
private final SubversionClientService subversionClientService;
private NotificationManager notificationManager;
private SubversionExtensionLocalizationConstants constants;
private final String baseHttpUrl;
Expand All @@ -50,10 +61,14 @@ public ExportPresenter(@Named("cheExtensionPath") String extPath,
ConsolesPanelPresenter consolesPanelPresenter,
ProjectExplorerPresenter projectExplorerPart,
ExportView view,
DtoUnmarshallerFactory dtoUnmarshallerFactory,
SubversionClientService subversionClientService,
NotificationManager notificationManager,
SubversionExtensionLocalizationConstants constants) {
super(appContext, consoleFactory, consolesPanelPresenter, projectExplorerPart);
this.view = view;
this.dtoUnmarshallerFactory = dtoUnmarshallerFactory;
this.subversionClientService = subversionClientService;
this.notificationManager = notificationManager;
this.constants = constants;
this.view.setDelegate(this);
Expand All @@ -79,29 +94,91 @@ public void onExportClicked() {
final String projectPath = getCurrentProjectPath();

if (projectPath == null) {
notificationManager.notify(constants.exportFailedNoProjectPath(), FAIL, true);
return;
}

final String exportPath = Strings.emptyToNull(relPath(projectPath, selectedNode.getStorablePath()));
final String revision = view.isRevisionSpecified() ? view.getRevision() : null;
final String nullableExportPath = emptyToNull(relPath(projectPath, selectedNode.getStorablePath()));
final String exportPath = (nullableExportPath != null ? nullableExportPath : ".");
final String givenRevision = view.isRevisionSpecified() ? view.getRevision() : null;

notificationManager.notify(constants.exportStarted(exportPath));
final StatusNotification notification = new StatusNotification(constants.exportStarted(exportPath), PROGRESS, true);
notificationManager.notify(notification);

view.onClose();

char prefix = '?';
StringBuilder url = new StringBuilder(baseHttpUrl + "/export" + projectPath);
if (!isNullOrEmpty(givenRevision)) {
final String path = getSelectedPaths().get(0);
subversionClientService.getRevisions(getActiveProject().getRootProject().getPath(), path, "1:HEAD",
new AsyncRequestCallback<GetRevisionsResponse>(
dtoUnmarshallerFactory.newUnmarshaller(GetRevisionsResponse.class)) {
@Override
protected void onSuccess(GetRevisionsResponse result) {
final List<String> pathRevisions = result.getRevisions();

if (pathRevisions.size() > 0) {
final String pathFirstRevision = pathRevisions.get(0);
final String pathLastRevision = pathRevisions.get(pathRevisions.size() - 1);

final int givenRevisionNb = Integer.valueOf(givenRevision);
final int pathFirstRevisionNb =
Integer.valueOf(pathFirstRevision.substring(1));
final int pathLastRevisionNb = Integer.valueOf(pathLastRevision.substring(1));

final List<String> errOutput = result.getErrOutput();
if (errOutput != null && !errOutput.isEmpty()) {
printErrors(errOutput, constants.commandInfo());
notification.setTitle(constants.exportCommandExecutionError());
notification.setStatus(FAIL);

} else if (givenRevisionNb < pathFirstRevisionNb ||
givenRevisionNb > pathLastRevisionNb) {
notification.setTitle(
constants.exportRevisionDoNotExistForPath(givenRevision, path));
notification.setStatus(FAIL);

} else {
openExportPopup(projectPath, exportPath, givenRevision, notification);
}
} else {
notification.setTitle(constants.exportNoRevisionForPath(exportPath));
notification.setStatus(FAIL);
}
}

@Override
protected void onFailure(Throwable exception) {
notification.setTitle(constants.exportCommandExecutionError() + "\n" +
exception.getLocalizedMessage());
notification.setStatus(FAIL);
}
});
} else {
openExportPopup(projectPath, exportPath, notification);
}
}

private void openExportPopup(final String projectPath, final String exportPath, final StatusNotification notification) {
openExportPopup(projectPath, exportPath, null, notification);
}

private void openExportPopup(final String projectPath, final String exportPath, final String revision,
final StatusNotification notification) {
final StringBuilder url = new StringBuilder(baseHttpUrl + "/export" + projectPath);

if (!Strings.isNullOrEmpty(exportPath)) {
url.append(prefix).append("path").append('=').append(exportPath);
prefix = '&';
char separator = '?';
if (!".".equals(exportPath)) {
url.append(separator).append("path").append('=').append(exportPath);
separator = '&';
}

if (!Strings.isNullOrEmpty(revision)) {
url.append(prefix).append("revision").append('=').append(revision);
if (!isNullOrEmpty(revision)) {
url.append(separator).append("revision").append('=').append(revision);
}

Window.open(url.toString(), "_self", "");
notification.setTitle(constants.exportSuccessful(exportPath));
notification.setStatus(SUCCESS);
}

/** {@inheritDoc} */
Expand Down
Loading

0 comments on commit 83d6cec

Please sign in to comment.