001    package org.apache.maven.scm.provider.integrity;
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.CommandParameter;
023    import org.apache.maven.scm.CommandParameters;
024    import org.apache.maven.scm.ScmException;
025    import org.apache.maven.scm.ScmFileSet;
026    import org.apache.maven.scm.ScmResult;
027    import org.apache.maven.scm.command.add.AddScmResult;
028    import org.apache.maven.scm.command.blame.BlameScmResult;
029    import org.apache.maven.scm.command.branch.BranchScmResult;
030    import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
031    import org.apache.maven.scm.command.checkin.CheckInScmResult;
032    import org.apache.maven.scm.command.checkout.CheckOutScmResult;
033    import org.apache.maven.scm.command.diff.DiffScmResult;
034    import org.apache.maven.scm.command.edit.EditScmResult;
035    import org.apache.maven.scm.command.export.ExportScmResult;
036    import org.apache.maven.scm.command.list.ListScmResult;
037    import org.apache.maven.scm.command.login.LoginScmResult;
038    import org.apache.maven.scm.command.mkdir.MkdirScmResult;
039    import org.apache.maven.scm.command.remove.RemoveScmResult;
040    import org.apache.maven.scm.command.status.StatusScmResult;
041    import org.apache.maven.scm.command.tag.TagScmResult;
042    import org.apache.maven.scm.command.unedit.UnEditScmResult;
043    import org.apache.maven.scm.command.update.UpdateScmResult;
044    import org.apache.maven.scm.provider.AbstractScmProvider;
045    import org.apache.maven.scm.provider.ScmProviderRepository;
046    import org.apache.maven.scm.provider.integrity.command.add.IntegrityAddCommand;
047    import org.apache.maven.scm.provider.integrity.command.blame.IntegrityBlameCommand;
048    import org.apache.maven.scm.provider.integrity.command.branch.IntegrityBranchCommand;
049    import org.apache.maven.scm.provider.integrity.command.changelog.IntegrityChangeLogCommand;
050    import org.apache.maven.scm.provider.integrity.command.checkin.IntegrityCheckInCommand;
051    import org.apache.maven.scm.provider.integrity.command.checkout.IntegrityCheckOutCommand;
052    import org.apache.maven.scm.provider.integrity.command.diff.IntegrityDiffCommand;
053    import org.apache.maven.scm.provider.integrity.command.edit.IntegrityEditCommand;
054    import org.apache.maven.scm.provider.integrity.command.export.IntegrityExportCommand;
055    import org.apache.maven.scm.provider.integrity.command.fileinfo.IntegrityFileInfoCommand;
056    import org.apache.maven.scm.provider.integrity.command.list.IntegrityListCommand;
057    import org.apache.maven.scm.provider.integrity.command.lock.IntegrityLockCommand;
058    import org.apache.maven.scm.provider.integrity.command.login.IntegrityLoginCommand;
059    import org.apache.maven.scm.provider.integrity.command.mkdir.IntegrityMkdirCommand;
060    import org.apache.maven.scm.provider.integrity.command.remove.IntegrityRemoveCommand;
061    import org.apache.maven.scm.provider.integrity.command.status.IntegrityStatusCommand;
062    import org.apache.maven.scm.provider.integrity.command.tag.IntegrityTagCommand;
063    import org.apache.maven.scm.provider.integrity.command.unedit.IntegrityUnEditCommand;
064    import org.apache.maven.scm.provider.integrity.command.unlock.IntegrityUnlockCommand;
065    import org.apache.maven.scm.provider.integrity.command.update.IntegrityUpdateCommand;
066    import org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository;
067    import org.apache.maven.scm.repository.ScmRepositoryException;
068    import org.codehaus.plexus.util.StringUtils;
069    
070    /**
071     * MKS Integrity SCM Provider for Maven
072     *
073     * @author <a href="mailto:cletus@mks.com">Cletus D'Souza</a>
074     * @version $Id: IntegrityScmProvider.java 1.7 2011/08/22 13:06:46EDT Cletus D'Souza (dsouza) Exp  $
075     * @plexus.component role="org.apache.maven.scm.provider.ScmProvider" role-hint="integrity"
076     * @since 1.6
077     */
078    public class IntegrityScmProvider
079        extends AbstractScmProvider
080    {
081        public static final String INTEGRITY_CM_URL = "[[user][/pass]@host[:port]]|configPath";
082    
083        /**
084         * Returns the name of our SCM Provider
085         */
086        public String getScmType()
087        {
088            return "integrity";
089        }
090    
091        /**
092         * This class is the central point of the SCM provider. The Maven-SCM framework will know only this class in the provider,
093         * so this class will validate the scm url, populate the IntegrityScmProviderRepository and provide all commands that we support.
094         *
095         * @param scmSpecificUrl The SCM URL specific to our implementation for this plugin
096         * @param delimiter      The character that separates the information above
097         * @throws ScmRepositoryException
098         */
099        public ScmProviderRepository makeProviderScmRepository( String scmSpecificUrl, char delimiter )
100            throws ScmRepositoryException
101        {
102            // Initialize our variables need to create the IntegrityScmProvderRepository
103            String hostName = "";
104            int port = 0;
105            String userName = "";
106            String password = "";
107            String configPath = "";
108    
109            // Looking for a string in the following format:
110            //      [[user][/pass]@host[:port]]|configPath
111            // Where '|' is the delimiter...
112            String[] tokens = StringUtils.split( scmSpecificUrl, String.valueOf( delimiter ) );
113            // Expecting a minimum of one token to a maximum of two tokens
114            if ( tokens.length < 1 || tokens.length > 2 )
115            {
116                throw new ScmRepositoryException(
117                    "Invalid SCM URL '" + scmSpecificUrl + "'.  Expecting a url using format: " + INTEGRITY_CM_URL );
118            }
119            else
120            {
121                // Inspect the first token to see if it contains connection information
122                if ( tokens[0].indexOf( '@' ) >= 0 )
123                {
124                    // First split up the username and password string from the host:port information
125                    String userPassStr = tokens[0].substring( 0, tokens[0].indexOf( '@' ) );
126                    getLogger().debug( "User/Password information supplied: " + userPassStr );
127                    String hostPortStr = tokens[0].substring( tokens[0].indexOf( '@' ) + 1, tokens[0].length() );
128                    getLogger().debug( "Host/Port information supplied: " + hostPortStr );
129    
130                    if ( userPassStr.length() > 0 )
131                    {
132                        // Next, make sure the username and password are separated using a forward slash '/'
133                        int userPassDelimIndx = userPassStr.indexOf( '/' );
134                        if ( userPassDelimIndx > 0 )
135                        {
136                            userName = userPassStr.substring( 0, userPassStr.indexOf( '/' ) );
137                            if ( userPassStr.length() > ( userPassDelimIndx + 1 ) )
138                            {
139                                password = userPassStr.substring( userPassStr.indexOf( '/' ) + 1, userPassStr.length() );
140                            }
141                        }
142                        else
143                        {
144                            userName = userPassStr;
145                        }
146                    }
147                    // Now, check to see what we've got for the host:port information
148                    if ( hostPortStr.length() > 0 )
149                    {
150                        int hostPortDelimIndx = hostPortStr.indexOf( ':' );
151                        if ( hostPortDelimIndx > 0 )
152                        {
153                            hostName = hostPortStr.substring( 0, hostPortStr.indexOf( ':' ) );
154                            if ( hostPortStr.length() > ( hostPortDelimIndx + 1 ) )
155                            {
156                                port = Integer.parseInt(
157                                    hostPortStr.substring( hostPortStr.indexOf( ':' ) + 1, hostPortStr.length() ) );
158                            }
159                        }
160                        else
161                        {
162                            hostName = hostPortStr;
163                        }
164                    }
165                }
166                // Grab the last token (or first token depends how you look at it)
167                configPath = tokens[tokens.length - 1];
168            }
169    
170            return new IntegrityScmProviderRepository( hostName, port, userName, password, configPath, getLogger() );
171        }
172    
173        /**
174         * Maps to si connect and initialization of the project with si projectinfo
175         */
176        @Override
177        protected LoginScmResult login( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params )
178            throws ScmException
179        {
180            IntegrityLoginCommand command = new IntegrityLoginCommand();
181            command.setLogger( getLogger() );
182            return (LoginScmResult) command.execute( repository, fileSet, params );
183        }
184    
185        /**
186         * Maps to si rlog --rfilter=daterange:date1-date2
187         */
188        @Override
189        protected ChangeLogScmResult changelog( ScmProviderRepository repository, ScmFileSet fileSet,
190                                                CommandParameters parameters )
191            throws ScmException
192        {
193            IntegrityChangeLogCommand command = new IntegrityChangeLogCommand();
194            command.setLogger( getLogger() );
195            return (ChangeLogScmResult) command.execute( repository, fileSet, parameters );
196        }
197    
198        /**
199         * Maps to si viewnonmembers and then si add for every non-member
200         */
201        @Override
202        public AddScmResult add( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params )
203            throws ScmException
204        {
205            IntegrityAddCommand command = new IntegrityAddCommand();
206            command.setLogger( getLogger() );
207            return (AddScmResult) command.execute( repository, fileSet, params );
208        }
209    
210        /**
211         * Maps to si dropsandbox
212         */
213        @Override
214        protected RemoveScmResult remove( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params )
215            throws ScmException
216        {
217            IntegrityRemoveCommand command = new IntegrityRemoveCommand();
218            command.setLogger( getLogger() );
219            return (RemoveScmResult) command.execute( repository, fileSet, params );
220        }
221    
222    
223        /**
224         * Maps to a si ci
225         */
226        @Override
227        protected CheckInScmResult checkin( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params )
228            throws ScmException
229        {
230            IntegrityCheckInCommand command = new IntegrityCheckInCommand();
231            command.setLogger( getLogger() );
232            return (CheckInScmResult) command.execute( repository, fileSet, params );
233        }
234    
235        /**
236         * Maps to si createsandbox and/or si resync
237         */
238        @Override
239        protected CheckOutScmResult checkout( ScmProviderRepository repository, ScmFileSet fileSet,
240                                              CommandParameters params )
241            throws ScmException
242        {
243            IntegrityCheckOutCommand command = new IntegrityCheckOutCommand();
244            command.setLogger( getLogger() );
245            return (CheckOutScmResult) command.execute( repository, fileSet, params );
246        }
247    
248        /**
249         * Maps to si diff
250         */
251        @Override
252        protected DiffScmResult diff( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params )
253            throws ScmException
254        {
255            IntegrityDiffCommand command = new IntegrityDiffCommand();
256            command.setLogger( getLogger() );
257            return (DiffScmResult) command.execute( repository, fileSet, params );
258        }
259    
260        /**
261         * Maps to si makewritable
262         */
263        @Override
264        protected EditScmResult edit( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params )
265            throws ScmException
266        {
267            IntegrityEditCommand command = new IntegrityEditCommand();
268            command.setLogger( getLogger() );
269            return (EditScmResult) command.execute( repository, fileSet, params );
270        }
271    
272        /**
273         * Maps to si viewsandbox with a filter of locally changed files
274         */
275        @Override
276        protected StatusScmResult status( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params )
277            throws ScmException
278        {
279            IntegrityStatusCommand command = new IntegrityStatusCommand();
280            command.setLogger( getLogger() );
281            return (StatusScmResult) command.execute( repository, fileSet, params );
282        }
283    
284        /**
285         * Maps to si checkpoint
286         */
287        @Override
288        protected TagScmResult tag( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params )
289            throws ScmException
290        {
291            IntegrityTagCommand command = new IntegrityTagCommand();
292            command.setLogger( getLogger() );
293            return (TagScmResult) command.execute( repository, fileSet, params );
294        }
295    
296        /**
297         * Maps to si revert
298         */
299        @Override
300        protected UnEditScmResult unedit( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params )
301            throws ScmException
302        {
303            IntegrityUnEditCommand command = new IntegrityUnEditCommand();
304            command.setLogger( getLogger() );
305            return (UnEditScmResult) command.execute( repository, fileSet, params );
306        }
307    
308        /**
309         * Maps to si resync
310         */
311        @Override
312        protected UpdateScmResult update( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params )
313            throws ScmException
314        {
315            IntegrityUpdateCommand command = new IntegrityUpdateCommand();
316            command.setLogger( getLogger() );
317            return (UpdateScmResult) command.execute( repository, fileSet, params );
318        }
319    
320        /**
321         * Maps to si annotate
322         */
323        @Override
324        protected BlameScmResult blame( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params )
325            throws ScmException
326        {
327            IntegrityBlameCommand command = new IntegrityBlameCommand();
328            command.setLogger( getLogger() );
329            return (BlameScmResult) command.execute( repository, fileSet, params );
330        }
331    
332        /**
333         * Maps to si viewproject
334         */
335        @Override
336        protected ListScmResult list( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params )
337            throws ScmException
338        {
339            IntegrityListCommand command = new IntegrityListCommand();
340            command.setLogger( getLogger() );
341            return (ListScmResult) command.execute( repository, fileSet, params );
342        }
343    
344        /**
345         * Maps to si projectco (no sandbox is used)
346         */
347        @Override
348        protected ExportScmResult export( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params )
349            throws ScmException
350        {
351            IntegrityExportCommand command = new IntegrityExportCommand();
352            command.setLogger( getLogger() );
353            return (ExportScmResult) command.execute( repository, fileSet, params );
354        }
355    
356        /**
357         * Maps to si createdevpath
358         */
359        @Override
360        protected BranchScmResult branch( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params )
361            throws ScmException
362        {
363            IntegrityBranchCommand command = new IntegrityBranchCommand();
364            command.setLogger( getLogger() );
365            return (BranchScmResult) command.execute( repository, fileSet, params );
366        }
367    
368        /**
369         * Maps to si createsubproject
370         */
371        @Override
372        protected MkdirScmResult mkdir( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params )
373            throws ScmException
374        {
375            IntegrityMkdirCommand command = new IntegrityMkdirCommand();
376            command.setLogger( getLogger() );
377            return (MkdirScmResult) command.execute( repository, fileSet, params );
378        }
379    
380        /**
381         * Maps to si memberinfo
382         */
383        protected ScmResult fileinfo( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params )
384            throws ScmException
385        {
386            IntegrityFileInfoCommand command = new IntegrityFileInfoCommand();
387            command.setLogger( getLogger() );
388            return command.execute( repository, fileSet, params );
389        }
390    
391        /**
392         * Maps to si lock
393         */
394        protected ScmResult lock( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params )
395            throws ScmException
396        {
397            IntegrityLockCommand command = new IntegrityLockCommand();
398            command.setLogger( getLogger() );
399            return command.execute( repository, fileSet, params );
400        }
401    
402        /**
403         * Maps to si unlock
404         */
405        protected ScmResult unlock( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params )
406            throws ScmException
407        {
408            IntegrityUnlockCommand command = new IntegrityUnlockCommand( params.getString( CommandParameter.FILE ) );
409            command.setLogger( getLogger() );
410            return command.execute( repository, fileSet, params );
411        }
412    }