1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.scm.provider.git.gitexe;
20
21 import javax.inject.Named;
22 import javax.inject.Singleton;
23
24 import java.io.File;
25 import java.util.HashMap;
26 import java.util.Map;
27
28 import org.apache.maven.scm.ScmException;
29 import org.apache.maven.scm.ScmFileSet;
30 import org.apache.maven.scm.command.info.InfoScmResult;
31 import org.apache.maven.scm.provider.git.AbstractGitScmProvider;
32 import org.apache.maven.scm.provider.git.command.GitCommand;
33 import org.apache.maven.scm.provider.git.gitexe.command.add.GitAddCommand;
34 import org.apache.maven.scm.provider.git.gitexe.command.blame.GitBlameCommand;
35 import org.apache.maven.scm.provider.git.gitexe.command.branch.GitBranchCommand;
36 import org.apache.maven.scm.provider.git.gitexe.command.changelog.GitChangeLogCommand;
37 import org.apache.maven.scm.provider.git.gitexe.command.checkin.GitCheckInCommand;
38 import org.apache.maven.scm.provider.git.gitexe.command.checkout.GitCheckOutCommand;
39 import org.apache.maven.scm.provider.git.gitexe.command.diff.GitDiffCommand;
40 import org.apache.maven.scm.provider.git.gitexe.command.info.GitInfoCommand;
41 import org.apache.maven.scm.provider.git.gitexe.command.remoteinfo.GitRemoteInfoCommand;
42 import org.apache.maven.scm.provider.git.gitexe.command.remove.GitRemoveCommand;
43 import org.apache.maven.scm.provider.git.gitexe.command.status.GitStatusCommand;
44 import org.apache.maven.scm.provider.git.gitexe.command.tag.GitTagCommand;
45 import org.apache.maven.scm.provider.git.gitexe.command.untag.GitUntagCommand;
46 import org.apache.maven.scm.provider.git.gitexe.command.update.GitUpdateCommand;
47 import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
48 import org.apache.maven.scm.repository.ScmRepositoryException;
49
50
51
52
53 @Singleton
54 @Named("git")
55 public class GitExeScmProvider extends AbstractGitScmProvider {
56 private final Map<String, String> environmentVariables;
57
58 public GitExeScmProvider() {
59 environmentVariables = new HashMap<>();
60 }
61
62
63 protected GitCommand getAddCommand() {
64 return new GitAddCommand();
65 }
66
67
68 protected GitCommand getBranchCommand() {
69 return new GitBranchCommand();
70 }
71
72
73 protected GitCommand getChangeLogCommand() {
74 return new GitChangeLogCommand();
75 }
76
77
78 protected GitCommand getCheckInCommand() {
79 return new GitCheckInCommand(environmentVariables);
80 }
81
82
83 protected GitCommand getCheckOutCommand() {
84 return new GitCheckOutCommand(environmentVariables);
85 }
86
87
88 protected GitCommand getDiffCommand() {
89 return new GitDiffCommand();
90 }
91
92
93 protected GitCommand getExportCommand() {
94 return null;
95 }
96
97
98 protected GitCommand getRemoveCommand() {
99 return new GitRemoveCommand();
100 }
101
102
103 protected GitCommand getStatusCommand() {
104 return new GitStatusCommand();
105 }
106
107
108 protected GitCommand getTagCommand() {
109 return new GitTagCommand();
110 }
111
112
113 protected GitCommand getUntagCommand() {
114 return new GitUntagCommand();
115 }
116
117
118 protected GitCommand getUpdateCommand() {
119 return new GitUpdateCommand();
120 }
121
122
123 public GitCommand getInfoCommand() {
124 return new GitInfoCommand();
125 }
126
127
128 protected GitCommand getBlameCommand() {
129 return new GitBlameCommand();
130 }
131
132
133 protected GitCommand getRemoteInfoCommand() {
134 return new GitRemoteInfoCommand(environmentVariables);
135 }
136
137
138 protected String getRepositoryURL(File path) throws ScmException {
139
140
141
142 InfoScmResult result =
143 info(new GitScmProviderRepository(path.toPath().toUri().toASCIIString()), new ScmFileSet(path), null);
144
145 if (result.getInfoItems().size() != 1) {
146 throw new ScmRepositoryException("Cannot find URL: "
147 + (result.getInfoItems().size() == 0 ? "no" : "multiple") + " items returned by the info command");
148 }
149
150 return result.getInfoItems().get(0).getURL();
151 }
152
153 public void setEnvironmentVariable(String key, String value) {
154 environmentVariables.put(key, value);
155 }
156 }