View Javadoc
1   package org.apache.maven.scm.provider.git.gitexe;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  
24  import org.apache.maven.scm.ScmException;
25  import org.apache.maven.scm.ScmFileSet;
26  import org.apache.maven.scm.command.info.InfoScmResult;
27  import org.apache.maven.scm.provider.git.AbstractGitScmProvider;
28  import org.apache.maven.scm.provider.git.command.GitCommand;
29  import org.apache.maven.scm.provider.git.gitexe.command.add.GitAddCommand;
30  import org.apache.maven.scm.provider.git.gitexe.command.blame.GitBlameCommand;
31  import org.apache.maven.scm.provider.git.gitexe.command.branch.GitBranchCommand;
32  import org.apache.maven.scm.provider.git.gitexe.command.changelog.GitChangeLogCommand;
33  import org.apache.maven.scm.provider.git.gitexe.command.checkin.GitCheckInCommand;
34  import org.apache.maven.scm.provider.git.gitexe.command.checkout.GitCheckOutCommand;
35  import org.apache.maven.scm.provider.git.gitexe.command.diff.GitDiffCommand;
36  import org.apache.maven.scm.provider.git.gitexe.command.info.GitInfoCommand;
37  import org.apache.maven.scm.provider.git.gitexe.command.list.GitListCommand;
38  import org.apache.maven.scm.provider.git.gitexe.command.remoteinfo.GitRemoteInfoCommand;
39  import org.apache.maven.scm.provider.git.gitexe.command.remove.GitRemoveCommand;
40  import org.apache.maven.scm.provider.git.gitexe.command.status.GitStatusCommand;
41  import org.apache.maven.scm.provider.git.gitexe.command.tag.GitTagCommand;
42  import org.apache.maven.scm.provider.git.gitexe.command.update.GitUpdateCommand;
43  import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
44  import org.apache.maven.scm.repository.ScmRepositoryException;
45  
46  /**
47   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
48   *
49   * @plexus.component role="org.apache.maven.scm.provider.ScmProvider" role-hint="git"
50   */
51  public class GitExeScmProvider
52      extends AbstractGitScmProvider
53  {
54      /** {@inheritDoc} */
55      protected GitCommand getAddCommand()
56      {
57          return new GitAddCommand();
58      }
59  
60      /** {@inheritDoc} */
61      protected GitCommand getBranchCommand()
62      {
63          return new GitBranchCommand();
64      }
65  
66      /** {@inheritDoc} */
67      protected GitCommand getChangeLogCommand()
68      {
69          return new GitChangeLogCommand();
70      }
71  
72      /** {@inheritDoc} */
73      protected GitCommand getCheckInCommand()
74      {
75          return new GitCheckInCommand();
76      }
77  
78      /** {@inheritDoc} */
79      protected GitCommand getCheckOutCommand()
80      {
81          return new GitCheckOutCommand();
82      }
83  
84      /** {@inheritDoc} */
85      protected GitCommand getDiffCommand()
86      {
87          return new GitDiffCommand();
88      }
89  
90      /** {@inheritDoc} */
91      protected GitCommand getExportCommand()
92      {
93          return null; //X TODO
94      }
95  
96      /** {@inheritDoc} */
97      protected GitCommand getRemoveCommand()
98      {
99          return new GitRemoveCommand();
100     }
101 
102     /** {@inheritDoc} */
103     protected GitCommand getStatusCommand()
104     {
105         return new GitStatusCommand();
106     }
107 
108     /** {@inheritDoc} */
109     protected GitCommand getTagCommand()
110     {
111         return new GitTagCommand();
112     }
113 
114     /** {@inheritDoc} */
115     protected GitCommand getUpdateCommand()
116     {
117         return new GitUpdateCommand();
118     }
119 
120     /** {@inheritDoc} */
121     protected GitCommand getListCommand()
122     {
123         return new GitListCommand();
124     }
125 
126     /** {@inheritDoc} */
127     public GitCommand getInfoCommand()
128     {
129         return new GitInfoCommand();
130     }
131 
132     /** {@inheritDoc} */
133     protected GitCommand getBlameCommand()
134     {
135         return new GitBlameCommand();
136     }
137 
138     /** {@inheritDoc} */
139     protected GitCommand getRemoteInfoCommand()
140     {
141         return new GitRemoteInfoCommand();
142     }
143 
144     /** {@inheritDoc} */
145     protected String getRepositoryURL( File path )
146         throws ScmException
147     {
148         // Note: I need to supply just 1 absolute path, but ScmFileSet won't let me without
149         // a basedir (which isn't used here anyway), so use a dummy file.
150         // and a dummy ScmProviderRepository
151         InfoScmResult result = info( new GitScmProviderRepository( path.getPath() ), new ScmFileSet( path ), null );
152 
153         if ( result.getInfoItems().size() != 1 )
154         {
155             throw new ScmRepositoryException( "Cannot find URL: "
156                 + ( result.getInfoItems().size() == 0 ? "no" : "multiple" ) + " items returned by the info command" );
157         }
158 
159         return result.getInfoItems().get( 0 ).getURL();
160     }
161 }