summaryrefslogtreecommitdiff
path: root/plugins/svn4idea/src/org/jetbrains/idea/svn/upgrade/SvnKitUpgradeClient.java
blob: f583ad2c8edab387d92df7459caf2305edddbe1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package org.jetbrains.idea.svn.upgrade;

import com.intellij.openapi.vcs.VcsException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.svn.WorkingCopyFormat;
import org.jetbrains.idea.svn.api.BaseSvnClient;
import org.jetbrains.idea.svn.api.EventAction;
import org.jetbrains.idea.svn.api.ProgressTracker;
import org.jetbrains.idea.svn.checkout.SvnKitCheckoutClient;
import org.jetbrains.idea.svn.commandLine.SvnBindException;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.wc.SVNWCClient;

import java.io.File;
import java.util.List;

/**
 * @author Konstantin Kolosovsky.
 */
public class SvnKitUpgradeClient extends BaseSvnClient implements UpgradeClient {

  @Override
  public void upgrade(@NotNull File path, @NotNull WorkingCopyFormat format, @Nullable ProgressTracker handler) throws VcsException {
    validateFormat(format, getSupportedFormats());

    SVNWCClient client = myVcs.getSvnKitManager().createWCClient();

    client.setEventHandler(toEventHandler(handler));
    try {
      cleanupIfNecessary(path, format, client, handler);
      upgrade(path, format, client, handler);
    }
    catch (SVNException e) {
      throw new SvnBindException(e);
    }
  }

  @Override
  public List<WorkingCopyFormat> getSupportedFormats() throws VcsException {
    return SvnKitCheckoutClient.SUPPORTED_FORMATS;
  }

  private static void cleanupIfNecessary(@NotNull File path,
                                         @NotNull WorkingCopyFormat format,
                                         @NotNull SVNWCClient client,
                                         @Nullable ProgressTracker handler) throws SVNException, VcsException {
    // cleanup is executed only for SVNKit as it could handle both 1.6 and 1.7 formats
    if (WorkingCopyFormat.ONE_DOT_SEVEN.equals(format)) {
      // fake event indicating cleanup start
      callHandler(handler, createEvent(path, EventAction.UPDATE_STARTED));
      client.doCleanup(path);
    }
  }

  private static void upgrade(@NotNull File path,
                              @NotNull WorkingCopyFormat format,
                              @NotNull SVNWCClient client,
                              @Nullable ProgressTracker handler) throws SVNException, VcsException {
    // fake event indicating upgrade start
    callHandler(handler, createEvent(path, EventAction.UPDATE_COMPLETED));
    client.doSetWCFormat(path, format.getFormat());
  }
}