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