001    package org.apache.maven.scm.provider.bazaar;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     * http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import org.apache.maven.scm.CommandParameters;
023    import org.apache.maven.scm.ScmException;
024    import org.apache.maven.scm.ScmFileSet;
025    import org.apache.maven.scm.ScmResult;
026    import org.apache.maven.scm.command.add.AddScmResult;
027    import org.apache.maven.scm.command.blame.BlameScmResult;
028    import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
029    import org.apache.maven.scm.command.checkin.CheckInScmResult;
030    import org.apache.maven.scm.command.checkout.CheckOutScmResult;
031    import org.apache.maven.scm.command.diff.DiffScmResult;
032    import org.apache.maven.scm.command.remove.RemoveScmResult;
033    import org.apache.maven.scm.command.status.StatusScmResult;
034    import org.apache.maven.scm.command.tag.TagScmResult;
035    import org.apache.maven.scm.command.update.UpdateScmResult;
036    import org.apache.maven.scm.provider.AbstractScmProvider;
037    import org.apache.maven.scm.provider.ScmProviderRepository;
038    import org.apache.maven.scm.provider.bazaar.command.BazaarConstants;
039    import org.apache.maven.scm.provider.bazaar.command.add.BazaarAddCommand;
040    import org.apache.maven.scm.provider.bazaar.command.blame.BazaarBlameCommand;
041    import org.apache.maven.scm.provider.bazaar.command.changelog.BazaarChangeLogCommand;
042    import org.apache.maven.scm.provider.bazaar.command.checkin.BazaarCheckInCommand;
043    import org.apache.maven.scm.provider.bazaar.command.checkout.BazaarCheckOutCommand;
044    import org.apache.maven.scm.provider.bazaar.command.diff.BazaarDiffCommand;
045    import org.apache.maven.scm.provider.bazaar.command.remove.BazaarRemoveCommand;
046    import org.apache.maven.scm.provider.bazaar.command.status.BazaarStatusCommand;
047    import org.apache.maven.scm.provider.bazaar.command.tag.BazaarTagCommand;
048    import org.apache.maven.scm.provider.bazaar.command.update.BazaarUpdateCommand;
049    import org.apache.maven.scm.provider.bazaar.repository.BazaarScmProviderRepository;
050    import org.apache.maven.scm.repository.ScmRepositoryException;
051    import org.apache.maven.scm.repository.UnknownRepositoryStructure;
052    
053    import java.io.File;
054    import java.util.ArrayList;
055    import java.util.List;
056    
057    /**
058     * Bazaar NG http://bazaar-vcs.org/ is a decentralized revision control system. <br>
059     *
060     * @author <a href="mailto:torbjorn@smorgrav.org">Torbj�rn Eikli Sm�rgrav</a>
061     * @version $Id: BazaarScmProvider.java 1056992 2011-01-09 18:09:41Z olamy $
062     * @plexus.component role="org.apache.maven.scm.provider.ScmProvider" role-hint="bazaar"
063     */
064    public class BazaarScmProvider
065        extends AbstractScmProvider
066    {
067        /** {@inheritDoc} */
068        public String getScmSpecificFilename()
069        {
070            return ".bzr";
071        }
072    
073        /** {@inheritDoc} */
074        public ScmProviderRepository makeProviderScmRepository( String scmSpecificUrl, char delimiter )
075            throws ScmRepositoryException
076        {
077            return new BazaarScmProviderRepository( scmSpecificUrl );
078        }
079    
080        /** {@inheritDoc} */
081        public ScmProviderRepository makeProviderScmRepository( File path )
082            throws ScmRepositoryException, UnknownRepositoryStructure
083        {
084            if ( path == null || !path.isDirectory() )
085            {
086                throw new ScmRepositoryException( path.getAbsolutePath() + " isn't a valid directory." );
087            }
088    
089            File bzrDir = new File( path, ".bzr" );
090    
091            if ( !bzrDir.exists() )
092            {
093                throw new ScmRepositoryException( path.getAbsolutePath() + " isn't a bazaar directory." );
094            }
095    
096            return makeProviderScmRepository( "file:///" + path.getAbsolutePath(), ':' );
097        }
098    
099        /** {@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    }