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 )
85          {
86              throw new NullPointerException( "Path argument is null" );
87          }
88  
89          if ( !path.isDirectory() )
90          {
91              throw new ScmRepositoryException( path.getAbsolutePath() + " isn't a valid directory." );
92          }
93  
94          File bzrDir = new File( path, ".bzr" );
95  
96          if ( !bzrDir.exists() )
97          {
98              throw new ScmRepositoryException( path.getAbsolutePath() + " isn't a bazaar directory." );
99          }
100 
101         return makeProviderScmRepository( "file:///" + path.getAbsolutePath(), ':' );
102     }
103 
104     /** {@inheritDoc} */
105     public List<String> validateScmUrl( String scmSpecificUrl, char delimiter )
106     {
107 
108         List<String> errorMessages = new ArrayList<String>();
109 
110         String[] checkCmd = new String[]{BazaarConstants.CHECK, scmSpecificUrl};
111         ScmResult result;
112         try
113         {
114             File tmpDir = new File( System.getProperty( "java.io.tmpdir" ) );
115             result = BazaarUtils.execute( tmpDir, checkCmd );
116             if ( !result.isSuccess() )
117             {
118                 errorMessages.add( result.getCommandOutput() );
119                 errorMessages.add( result.getProviderMessage() );
120             }
121         }
122         catch ( ScmException e )
123         {
124             errorMessages.add( e.getMessage() );
125         }
126 
127         return errorMessages;
128     }
129 
130     /** {@inheritDoc} */
131     public String getScmType()
132     {
133         return "bazaar";
134     }
135 
136     /** {@inheritDoc} */
137     public AddScmResult add( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
138         throws ScmException
139     {
140         BazaarAddCommand command = new BazaarAddCommand();
141 
142         command.setLogger( getLogger() );
143 
144         return (AddScmResult) command.execute( repository, fileSet, parameters );
145     }
146 
147     /** {@inheritDoc} */
148     public ChangeLogScmResult changelog( ScmProviderRepository repository, ScmFileSet fileSet,
149                                          CommandParameters parameters )
150         throws ScmException
151     {
152         BazaarChangeLogCommand command = new BazaarChangeLogCommand();
153 
154         command.setLogger( getLogger() );
155 
156         return (ChangeLogScmResult) command.execute( repository, fileSet, parameters );
157     }
158 
159     /** {@inheritDoc} */
160     public CheckInScmResult checkin( ScmProviderRepository repository, ScmFileSet fileSet,
161                                      CommandParameters parameters )
162         throws ScmException
163     {
164         BazaarCheckInCommand command = new BazaarCheckInCommand();
165 
166         command.setLogger( getLogger() );
167 
168         return (CheckInScmResult) command.execute( repository, fileSet, parameters );
169     }
170 
171     /** {@inheritDoc} */
172     public CheckOutScmResult checkout( ScmProviderRepository repository, ScmFileSet fileSet,
173                                        CommandParameters parameters )
174         throws ScmException
175     {
176         BazaarCheckOutCommand command = new BazaarCheckOutCommand();
177 
178         command.setLogger( getLogger() );
179 
180         return (CheckOutScmResult) command.execute( repository, fileSet, parameters );
181     }
182 
183     /** {@inheritDoc} */
184     public DiffScmResult diff( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
185         throws ScmException
186     {
187         BazaarDiffCommand command = new BazaarDiffCommand();
188 
189         command.setLogger( getLogger() );
190 
191         return (DiffScmResult) command.execute( repository, fileSet, parameters );
192     }
193 
194     /** {@inheritDoc} */
195     public RemoveScmResult remove( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
196         throws ScmException
197     {
198         BazaarRemoveCommand command = new BazaarRemoveCommand();
199 
200         command.setLogger( getLogger() );
201 
202         return (RemoveScmResult) command.execute( repository, fileSet, parameters );
203     }
204 
205     /** {@inheritDoc} */
206     public StatusScmResult status( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
207         throws ScmException
208     {
209         BazaarStatusCommand command = new BazaarStatusCommand();
210 
211         command.setLogger( getLogger() );
212 
213         return (StatusScmResult) command.execute( repository, fileSet, parameters );
214     }
215 
216     /** {@inheritDoc} */
217     public TagScmResult tag( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
218         throws ScmException
219     {
220         BazaarTagCommand command = new BazaarTagCommand();
221 
222         command.setLogger( getLogger() );
223 
224         return (TagScmResult) command.execute( repository, fileSet, parameters );
225     }
226 
227     /** {@inheritDoc} */
228     public UpdateScmResult update( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
229         throws ScmException
230     {
231         BazaarUpdateCommand command = new BazaarUpdateCommand();
232 
233         command.setLogger( getLogger() );
234 
235         return (UpdateScmResult) command.execute( repository, fileSet, parameters );
236     }
237 
238     /** {@inheritDoc} */
239     protected BlameScmResult blame( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
240         throws ScmException
241     {
242         BazaarBlameCommand command = new BazaarBlameCommand();
243 
244         command.setLogger( getLogger() );
245 
246         return (BlameScmResult) command.execute( repository, fileSet, parameters );
247     }
248 }