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