1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.linecorp.centraldogma.server.internal.mirror;
18
19 import static com.linecorp.centraldogma.server.internal.storage.repository.MirrorUtil.split;
20 import static com.linecorp.centraldogma.server.mirror.MirrorSchemes.SCHEME_GIT;
21 import static com.linecorp.centraldogma.server.mirror.MirrorSchemes.SCHEME_GIT_FILE;
22 import static com.linecorp.centraldogma.server.mirror.MirrorSchemes.SCHEME_GIT_HTTP;
23 import static com.linecorp.centraldogma.server.mirror.MirrorSchemes.SCHEME_GIT_HTTPS;
24 import static com.linecorp.centraldogma.server.mirror.MirrorSchemes.SCHEME_GIT_SSH;
25 import static java.util.Objects.requireNonNull;
26
27 import java.net.URI;
28
29 import com.linecorp.centraldogma.server.mirror.Mirror;
30 import com.linecorp.centraldogma.server.mirror.MirrorContext;
31 import com.linecorp.centraldogma.server.mirror.MirrorProvider;
32
33 public final class GitMirrorProvider implements MirrorProvider {
34
35 @Override
36 public Mirror newMirror(MirrorContext context) {
37 requireNonNull(context, "context");
38
39 final URI remoteUri = context.remoteUri();
40 final String scheme = remoteUri.getScheme();
41 if (scheme == null) {
42 return null;
43 }
44
45 switch (scheme) {
46 case SCHEME_GIT_SSH: {
47 final String[] components = split(remoteUri, "git");
48 return new SshGitMirror(context.schedule(), context.direction(), context.credential(),
49 context.localRepo(), context.localPath(),
50 URI.create(components[0]), components[1], components[2],
51 context.gitignore());
52 }
53 case SCHEME_GIT_HTTP:
54 case SCHEME_GIT_HTTPS:
55 case SCHEME_GIT:
56 case SCHEME_GIT_FILE: {
57 final String[] components = split(remoteUri, "git");
58 return new DefaultGitMirror(context.schedule(), context.direction(), context.credential(),
59 context.localRepo(), context.localPath(),
60 URI.create(components[0]), components[1], components[2],
61 context.gitignore());
62 }
63 }
64
65 return null;
66 }
67 }