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