View Javadoc
1   package org.apache.maven.scm.provider.git.jgit;
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.command.info.GitInfoItem;
30  import org.apache.maven.scm.provider.git.jgit.command.add.JGitAddCommand;
31  import org.apache.maven.scm.provider.git.jgit.command.blame.JGitBlameCommand;
32  import org.apache.maven.scm.provider.git.jgit.command.branch.JGitBranchCommand;
33  import org.apache.maven.scm.provider.git.jgit.command.changelog.JGitChangeLogCommand;
34  import org.apache.maven.scm.provider.git.jgit.command.checkin.JGitCheckInCommand;
35  import org.apache.maven.scm.provider.git.jgit.command.checkout.JGitCheckOutCommand;
36  import org.apache.maven.scm.provider.git.jgit.command.diff.JGitDiffCommand;
37  import org.apache.maven.scm.provider.git.jgit.command.info.JGitInfoCommand;
38  import org.apache.maven.scm.provider.git.jgit.command.list.JGitListCommand;
39  import org.apache.maven.scm.provider.git.jgit.command.remoteinfo.JGitRemoteInfoCommand;
40  import org.apache.maven.scm.provider.git.jgit.command.status.JGitStatusCommand;
41  import org.apache.maven.scm.provider.git.jgit.command.tag.JGitTagCommand;
42  import org.apache.maven.scm.provider.git.jgit.command.untag.JGitUntagCommand;
43  import org.apache.maven.scm.repository.ScmRepositoryException;
44  
45  /**
46   * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
47   * @author Dominik Bartholdi (imod)
48   * @plexus.component role="org.apache.maven.scm.provider.ScmProvider" role-hint="jgit"
49   * @since 1.9
50   */
51  public class JGitScmProvider
52      extends AbstractGitScmProvider
53  {
54      /**
55       * {@inheritDoc}
56       */
57      protected GitCommand getAddCommand()
58      {
59          return new JGitAddCommand();
60      }
61  
62      /**
63       * {@inheritDoc}
64       */
65      protected GitCommand getBranchCommand()
66      {
67          return new JGitBranchCommand();
68      }
69  
70      /**
71       * {@inheritDoc}
72       */
73      protected GitCommand getChangeLogCommand()
74      {
75          return new JGitChangeLogCommand();
76      }
77  
78      /**
79       * {@inheritDoc}
80       */
81      protected GitCommand getCheckInCommand()
82      {
83          return new JGitCheckInCommand();
84      }
85  
86      /**
87       * {@inheritDoc}
88       */
89      protected GitCommand getCheckOutCommand()
90      {
91          return new JGitCheckOutCommand();
92      }
93  
94      /**
95       * {@inheritDoc}
96       */
97      protected GitCommand getDiffCommand()
98      {
99          return new JGitDiffCommand();
100     }
101 
102     /**
103      * {@inheritDoc}
104      */
105     protected GitCommand getExportCommand()
106     {
107         throw new UnsupportedOperationException( "getExportCommand" );
108     }
109 
110     /**
111      * {@inheritDoc}
112      */
113     protected GitCommand getRemoveCommand()
114     {
115         throw new UnsupportedOperationException( "getRemoveCommand" );
116     }
117 
118     /**
119      * {@inheritDoc}
120      */
121     protected GitCommand getStatusCommand()
122     {
123         return new JGitStatusCommand();
124     }
125 
126     /**
127      * {@inheritDoc}
128      */
129     protected GitCommand getTagCommand()
130     {
131         return new JGitTagCommand();
132     }
133 
134     /**
135      * {@inheritDoc}
136      */
137     protected GitCommand getUntagCommand()
138     {
139         return new JGitUntagCommand();
140     }
141 
142     /**
143      * {@inheritDoc}
144      */
145     protected GitCommand getUpdateCommand()
146     {
147         throw new UnsupportedOperationException( "getUpdateCommand" );
148     }
149 
150     /**
151      * {@inheritDoc}
152      */
153     protected GitCommand getListCommand()
154     {
155         return new JGitListCommand();
156     }
157 
158     /**
159      * {@inheritDoc}
160      */
161     public GitCommand getInfoCommand()
162     {
163         return new JGitInfoCommand();
164     }
165 
166     /**
167      * {@inheritDoc}
168      */
169     protected String getRepositoryURL( File path )
170         throws ScmException
171     {
172         // Note: I need to supply just 1 absolute path, but ScmFileSet won't let
173         // me without
174         // a basedir (which isn't used here anyway), so use a dummy file.
175         InfoScmResult result = info( null, new ScmFileSet( new File( "" ), path ), null );
176 
177         if ( result.getInfoItems().size() != 1 )
178         {
179             throw new ScmRepositoryException(
180                 "Cannot find URL: " + ( result.getInfoItems().size() == 0 ? "no" : "multiple" )
181                     + " items returned by the info command" );
182         }
183 
184         return ( (GitInfoItem) result.getInfoItems().get( 0 ) ).getURL();
185     }
186 
187     /**
188      * {@inheritDoc}
189      */
190     protected GitCommand getBlameCommand()
191     {
192         return new JGitBlameCommand();
193     }
194 
195     /**
196      * {@inheritDoc}
197      */
198     protected GitCommand getRemoteInfoCommand()
199     {
200         return new JGitRemoteInfoCommand();
201     }
202 }