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.remoteinfo.GitRemoteInfoCommand;
38  import org.apache.maven.scm.provider.git.gitexe.command.remove.GitRemoveCommand;
39  import org.apache.maven.scm.provider.git.gitexe.command.status.GitStatusCommand;
40  import org.apache.maven.scm.provider.git.gitexe.command.tag.GitTagCommand;
41  import org.apache.maven.scm.provider.git.gitexe.command.update.GitUpdateCommand;
42  import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
43  import org.apache.maven.scm.repository.ScmRepositoryException;
44  
45  /**
46   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
47   *
48   * @plexus.component role="org.apache.maven.scm.provider.ScmProvider" role-hint="git"
49   */
50  public class GitExeScmProvider
51      extends AbstractGitScmProvider
52  {
53      /** {@inheritDoc} */
54      protected GitCommand getAddCommand()
55      {
56          return new GitAddCommand();
57      }
58  
59      /** {@inheritDoc} */
60      protected GitCommand getBranchCommand()
61      {
62          return new GitBranchCommand();
63      }
64  
65      /** {@inheritDoc} */
66      protected GitCommand getChangeLogCommand()
67      {
68          return new GitChangeLogCommand();
69      }
70  
71      /** {@inheritDoc} */
72      protected GitCommand getCheckInCommand()
73      {
74          return new GitCheckInCommand();
75      }
76  
77      /** {@inheritDoc} */
78      protected GitCommand getCheckOutCommand()
79      {
80          return new GitCheckOutCommand();
81      }
82  
83      /** {@inheritDoc} */
84      protected GitCommand getDiffCommand()
85      {
86          return new GitDiffCommand();
87      }
88  
89      /** {@inheritDoc} */
90      protected GitCommand getExportCommand()
91      {
92          return null; //X TODO
93      }
94  
95      /** {@inheritDoc} */
96      protected GitCommand getRemoveCommand()
97      {
98          return new GitRemoveCommand();
99      }
100 
101     /** {@inheritDoc} */
102     protected GitCommand getStatusCommand()
103     {
104         return new GitStatusCommand();
105     }
106 
107     /** {@inheritDoc} */
108     protected GitCommand getTagCommand()
109     {
110         return new GitTagCommand();
111     }
112 
113     /** {@inheritDoc} */
114     protected GitCommand getUpdateCommand()
115     {
116         return new GitUpdateCommand();
117     }
118 
119     /** {@inheritDoc} */
120     public GitCommand getInfoCommand()
121     {
122         return new GitInfoCommand();
123     }
124 
125     /** {@inheritDoc} */
126     protected GitCommand getBlameCommand()
127     {
128         return new GitBlameCommand();
129     }
130 
131     /** {@inheritDoc} */
132     protected GitCommand getRemoteInfoCommand()
133     {
134         return new GitRemoteInfoCommand();
135     }
136 
137     /** {@inheritDoc} */
138     protected String getRepositoryURL( File path )
139         throws ScmException
140     {
141         // Note: I need to supply just 1 absolute path, but ScmFileSet won't let me without
142         // a basedir (which isn't used here anyway), so use a dummy file.
143         // and a dummy ScmProviderRepository
144         InfoScmResult result = info( new GitScmProviderRepository( path.getPath() ), new ScmFileSet( path ), null );
145 
146         if ( result.getInfoItems().size() != 1 )
147         {
148             throw new ScmRepositoryException( "Cannot find URL: "
149                 + ( result.getInfoItems().size() == 0 ? "no" : "multiple" ) + " items returned by the info command" );
150         }
151 
152         return result.getInfoItems().get( 0 ).getURL();
153     }
154 }