View Javadoc
1   package org.apache.maven.scm.provider.bazaar;
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 org.apache.maven.scm.CommandParameters;
23  import org.apache.maven.scm.ScmException;
24  import org.apache.maven.scm.ScmFileSet;
25  import org.apache.maven.scm.ScmResult;
26  import org.apache.maven.scm.command.add.AddScmResult;
27  import org.apache.maven.scm.command.blame.BlameScmResult;
28  import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
29  import org.apache.maven.scm.command.checkin.CheckInScmResult;
30  import org.apache.maven.scm.command.checkout.CheckOutScmResult;
31  import org.apache.maven.scm.command.diff.DiffScmResult;
32  import org.apache.maven.scm.command.remove.RemoveScmResult;
33  import org.apache.maven.scm.command.status.StatusScmResult;
34  import org.apache.maven.scm.command.tag.TagScmResult;
35  import org.apache.maven.scm.command.update.UpdateScmResult;
36  import org.apache.maven.scm.provider.AbstractScmProvider;
37  import org.apache.maven.scm.provider.ScmProviderRepository;
38  import org.apache.maven.scm.provider.bazaar.command.BazaarConstants;
39  import org.apache.maven.scm.provider.bazaar.command.add.BazaarAddCommand;
40  import org.apache.maven.scm.provider.bazaar.command.blame.BazaarBlameCommand;
41  import org.apache.maven.scm.provider.bazaar.command.changelog.BazaarChangeLogCommand;
42  import org.apache.maven.scm.provider.bazaar.command.checkin.BazaarCheckInCommand;
43  import org.apache.maven.scm.provider.bazaar.command.checkout.BazaarCheckOutCommand;
44  import org.apache.maven.scm.provider.bazaar.command.diff.BazaarDiffCommand;
45  import org.apache.maven.scm.provider.bazaar.command.remove.BazaarRemoveCommand;
46  import org.apache.maven.scm.provider.bazaar.command.status.BazaarStatusCommand;
47  import org.apache.maven.scm.provider.bazaar.command.tag.BazaarTagCommand;
48  import org.apache.maven.scm.provider.bazaar.command.update.BazaarUpdateCommand;
49  import org.apache.maven.scm.provider.bazaar.repository.BazaarScmProviderRepository;
50  import org.apache.maven.scm.repository.ScmRepositoryException;
51  import org.apache.maven.scm.repository.UnknownRepositoryStructure;
52  
53  import java.io.File;
54  import java.util.ArrayList;
55  import java.util.List;
56  
57  /**
58   * Bazaar NG http://bazaar-vcs.org/ is a decentralized revision control system. <br>
59   *
60   * @author <a href="mailto:torbjorn@smorgrav.org">Torbjorn Eikli Smorgrav</a>
61   *
62   * @plexus.component role="org.apache.maven.scm.provider.ScmProvider" role-hint="bazaar"
63   */
64  public class BazaarScmProvider
65      extends AbstractScmProvider
66  {
67      /** {@inheritDoc} */
68      public String getScmSpecificFilename()
69      {
70          return ".bzr";
71      }
72  
73      /** {@inheritDoc} */
74      public ScmProviderRepository makeProviderScmRepository( String scmSpecificUrl, char delimiter )
75          throws ScmRepositoryException
76      {
77          return new BazaarScmProviderRepository( scmSpecificUrl );
78      }
79  
80      /** {@inheritDoc} */
81      public ScmProviderRepository makeProviderScmRepository( File path )
82          throws ScmRepositoryException, UnknownRepositoryStructure
83      {
84          if ( path == null || !path.isDirectory() )
85          {
86              throw new ScmRepositoryException( path.getAbsolutePath() + " isn't a valid directory." );
87          }
88  
89          File bzrDir = new File( path, ".bzr" );
90  
91          if ( !bzrDir.exists() )
92          {
93              throw new ScmRepositoryException( path.getAbsolutePath() + " isn't a bazaar directory." );
94          }
95  
96          return makeProviderScmRepository( "file:///" + path.getAbsolutePath(), ':' );
97      }
98  
99      /** {@inheritDoc} */
100     public List<String> validateScmUrl( String scmSpecificUrl, char delimiter )
101     {
102 
103         List<String> errorMessages = new ArrayList<String>();
104 
105         String[] checkCmd = new String[]{BazaarConstants.CHECK, scmSpecificUrl};
106         ScmResult result;
107         try
108         {
109             File tmpDir = new File( System.getProperty( "java.io.tmpdir" ) );
110             result = BazaarUtils.execute( tmpDir, checkCmd );
111             if ( !result.isSuccess() )
112             {
113                 errorMessages.add( result.getCommandOutput() );
114                 errorMessages.add( result.getProviderMessage() );
115             }
116         }
117         catch ( ScmException e )
118         {
119             errorMessages.add( e.getMessage() );
120         }
121 
122         return errorMessages;
123     }
124 
125     /** {@inheritDoc} */
126     public String getScmType()
127     {
128         return "bazaar";
129     }
130 
131     /** {@inheritDoc} */
132     public AddScmResult add( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
133         throws ScmException
134     {
135         BazaarAddCommand command = new BazaarAddCommand();
136 
137         command.setLogger( getLogger() );
138 
139         return (AddScmResult) command.execute( repository, fileSet, parameters );
140     }
141 
142     /** {@inheritDoc} */
143     public ChangeLogScmResult changelog( ScmProviderRepository repository, ScmFileSet fileSet,
144                                          CommandParameters parameters )
145         throws ScmException
146     {
147         BazaarChangeLogCommand command = new BazaarChangeLogCommand();
148 
149         command.setLogger( getLogger() );
150 
151         return (ChangeLogScmResult) command.execute( repository, fileSet, parameters );
152     }
153 
154     /** {@inheritDoc} */
155     public CheckInScmResult checkin( ScmProviderRepository repository, ScmFileSet fileSet,
156                                      CommandParameters parameters )
157         throws ScmException
158     {
159         BazaarCheckInCommand command = new BazaarCheckInCommand();
160 
161         command.setLogger( getLogger() );
162 
163         return (CheckInScmResult) command.execute( repository, fileSet, parameters );
164     }
165 
166     /** {@inheritDoc} */
167     public CheckOutScmResult checkout( ScmProviderRepository repository, ScmFileSet fileSet,
168                                        CommandParameters parameters )
169         throws ScmException
170     {
171         BazaarCheckOutCommand command = new BazaarCheckOutCommand();
172 
173         command.setLogger( getLogger() );
174 
175         return (CheckOutScmResult) command.execute( repository, fileSet, parameters );
176     }
177 
178     /** {@inheritDoc} */
179     public DiffScmResult diff( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
180         throws ScmException
181     {
182         BazaarDiffCommand command = new BazaarDiffCommand();
183 
184         command.setLogger( getLogger() );
185 
186         return (DiffScmResult) command.execute( repository, fileSet, parameters );
187     }
188 
189     /** {@inheritDoc} */
190     public RemoveScmResult remove( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
191         throws ScmException
192     {
193         BazaarRemoveCommand command = new BazaarRemoveCommand();
194 
195         command.setLogger( getLogger() );
196 
197         return (RemoveScmResult) command.execute( repository, fileSet, parameters );
198     }
199 
200     /** {@inheritDoc} */
201     public StatusScmResult status( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
202         throws ScmException
203     {
204         BazaarStatusCommand command = new BazaarStatusCommand();
205 
206         command.setLogger( getLogger() );
207 
208         return (StatusScmResult) command.execute( repository, fileSet, parameters );
209     }
210 
211     /** {@inheritDoc} */
212     public TagScmResult tag( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
213         throws ScmException
214     {
215         BazaarTagCommand command = new BazaarTagCommand();
216 
217         command.setLogger( getLogger() );
218 
219         return (TagScmResult) command.execute( repository, fileSet, parameters );
220     }
221 
222     /** {@inheritDoc} */
223     public UpdateScmResult update( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
224         throws ScmException
225     {
226         BazaarUpdateCommand command = new BazaarUpdateCommand();
227 
228         command.setLogger( getLogger() );
229 
230         return (UpdateScmResult) command.execute( repository, fileSet, parameters );
231     }
232 
233     /** {@inheritDoc} */
234     protected BlameScmResult blame( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
235         throws ScmException
236     {
237         BazaarBlameCommand command = new BazaarBlameCommand();
238 
239         command.setLogger( getLogger() );
240 
241         return (BlameScmResult) command.execute( repository, fileSet, parameters );
242     }
243 }