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.jgit;
20
21 import javax.inject.Inject;
22 import javax.inject.Named;
23 import javax.inject.Singleton;
24
25 import java.io.File;
26
27 import org.apache.maven.scm.ScmException;
28 import org.apache.maven.scm.ScmFileSet;
29 import org.apache.maven.scm.command.info.InfoScmResult;
30 import org.apache.maven.scm.provider.git.AbstractGitScmProvider;
31 import org.apache.maven.scm.provider.git.command.GitCommand;
32 import org.apache.maven.scm.provider.git.jgit.command.PlexusInteractivityCredentialsProvider;
33 import org.apache.maven.scm.provider.git.jgit.command.add.JGitAddCommand;
34 import org.apache.maven.scm.provider.git.jgit.command.blame.JGitBlameCommand;
35 import org.apache.maven.scm.provider.git.jgit.command.branch.JGitBranchCommand;
36 import org.apache.maven.scm.provider.git.jgit.command.changelog.JGitChangeLogCommand;
37 import org.apache.maven.scm.provider.git.jgit.command.checkin.JGitCheckInCommand;
38 import org.apache.maven.scm.provider.git.jgit.command.checkout.JGitCheckOutCommand;
39 import org.apache.maven.scm.provider.git.jgit.command.diff.JGitDiffCommand;
40 import org.apache.maven.scm.provider.git.jgit.command.info.JGitInfoCommand;
41 import org.apache.maven.scm.provider.git.jgit.command.list.JGitListCommand;
42 import org.apache.maven.scm.provider.git.jgit.command.remoteinfo.JGitRemoteInfoCommand;
43 import org.apache.maven.scm.provider.git.jgit.command.remove.JGitRemoveCommand;
44 import org.apache.maven.scm.provider.git.jgit.command.status.JGitStatusCommand;
45 import org.apache.maven.scm.provider.git.jgit.command.tag.JGitTagCommand;
46 import org.apache.maven.scm.provider.git.jgit.command.untag.JGitUntagCommand;
47 import org.apache.maven.scm.repository.ScmRepositoryException;
48 import org.codehaus.plexus.components.interactivity.Prompter;
49 import org.eclipse.jgit.transport.CredentialsProvider;
50
51
52
53
54
55
56 @Singleton
57 @Named("jgit")
58 public class JGitScmProvider extends AbstractGitScmProvider {
59 private final PlexusInteractivityCredentialsProvider credentialsProvider;
60
61 @Inject
62 public JGitScmProvider(Prompter prompter) {
63 credentialsProvider = new PlexusInteractivityCredentialsProvider(prompter);
64 CredentialsProvider.setDefault(credentialsProvider);
65 }
66
67 @Override
68 public void setInteractive(boolean interactive) {
69 credentialsProvider.setInteractive(interactive);
70 }
71
72
73
74
75 @Override
76 protected GitCommand getAddCommand() {
77 return new JGitAddCommand();
78 }
79
80
81
82
83 @Override
84 protected GitCommand getBranchCommand() {
85 return new JGitBranchCommand();
86 }
87
88
89
90
91 @Override
92 protected GitCommand getChangeLogCommand() {
93 return new JGitChangeLogCommand();
94 }
95
96
97
98
99 @Override
100 protected GitCommand getCheckInCommand() {
101 return new JGitCheckInCommand();
102 }
103
104
105
106
107 @Override
108 protected GitCommand getCheckOutCommand() {
109 return new JGitCheckOutCommand();
110 }
111
112
113
114
115 @Override
116 protected GitCommand getDiffCommand() {
117 return new JGitDiffCommand();
118 }
119
120
121
122
123 @Override
124 protected GitCommand getExportCommand() {
125 throw new UnsupportedOperationException("getExportCommand");
126 }
127
128
129
130
131 @Override
132 protected GitCommand getRemoveCommand() {
133 return new JGitRemoveCommand();
134 }
135
136
137
138
139 @Override
140 protected GitCommand getStatusCommand() {
141 return new JGitStatusCommand();
142 }
143
144
145
146
147 @Override
148 protected GitCommand getTagCommand() {
149 return new JGitTagCommand();
150 }
151
152
153
154
155 @Override
156 protected GitCommand getUntagCommand() {
157 return new JGitUntagCommand();
158 }
159
160
161
162
163 @Override
164 protected GitCommand getUpdateCommand() {
165 throw new UnsupportedOperationException("getUpdateCommand");
166 }
167
168
169
170
171 protected GitCommand getListCommand() {
172 return new JGitListCommand();
173 }
174
175
176
177
178 @Override
179 public GitCommand getInfoCommand() {
180 return new JGitInfoCommand();
181 }
182
183
184
185
186 @Override
187 protected String getRepositoryURL(File path) throws ScmException {
188
189
190
191 InfoScmResult result = info(null, new ScmFileSet(new File(""), path), null);
192
193 if (result.getInfoItems().size() != 1) {
194 throw new ScmRepositoryException("Cannot find URL: "
195 + (result.getInfoItems().size() == 0 ? "no" : "multiple") + " items returned by the info command");
196 }
197
198 return (result.getInfoItems().get(0)).getURL();
199 }
200
201
202
203
204 @Override
205 protected GitCommand getBlameCommand() {
206 return new JGitBlameCommand();
207 }
208
209
210
211
212 @Override
213 protected GitCommand getRemoteInfoCommand() {
214 return new JGitRemoteInfoCommand();
215 }
216 }