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