Coverage Report - org.apache.maven.scm.provider.cvslib.cvsexe.CvsExeScmProvider
 
Classes in this File Line Coverage Branch Coverage Complexity
CvsExeScmProvider
60 %
38/63
54 %
12/22
2
 
 1  
 package org.apache.maven.scm.provider.cvslib.cvsexe;
 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.command.Command;
 23  
 import org.apache.maven.scm.provider.cvslib.AbstractCvsScmProvider;
 24  
 import org.apache.maven.scm.provider.cvslib.command.login.CvsLoginCommand;
 25  
 import org.apache.maven.scm.provider.cvslib.cvsexe.command.add.CvsExeAddCommand;
 26  
 import org.apache.maven.scm.provider.cvslib.cvsexe.command.blame.CvsExeBlameCommand;
 27  
 import org.apache.maven.scm.provider.cvslib.cvsexe.command.branch.CvsExeBranchCommand;
 28  
 import org.apache.maven.scm.provider.cvslib.cvsexe.command.changelog.CvsExeChangeLogCommand;
 29  
 import org.apache.maven.scm.provider.cvslib.cvsexe.command.checkin.CvsExeCheckInCommand;
 30  
 import org.apache.maven.scm.provider.cvslib.cvsexe.command.checkout.CvsExeCheckOutCommand;
 31  
 import org.apache.maven.scm.provider.cvslib.cvsexe.command.diff.CvsExeDiffCommand;
 32  
 import org.apache.maven.scm.provider.cvslib.cvsexe.command.export.CvsExeExportCommand;
 33  
 import org.apache.maven.scm.provider.cvslib.cvsexe.command.list.CvsExeListCommand;
 34  
 import org.apache.maven.scm.provider.cvslib.cvsexe.command.mkdir.CvsExeMkdirCommand;
 35  
 import org.apache.maven.scm.provider.cvslib.cvsexe.command.remove.CvsExeRemoveCommand;
 36  
 import org.apache.maven.scm.provider.cvslib.cvsexe.command.status.CvsExeStatusCommand;
 37  
 import org.apache.maven.scm.provider.cvslib.cvsexe.command.tag.CvsExeTagCommand;
 38  
 import org.apache.maven.scm.provider.cvslib.cvsexe.command.update.CvsExeUpdateCommand;
 39  
 import org.apache.maven.scm.provider.cvslib.repository.CvsScmProviderRepository;
 40  
 import org.codehaus.plexus.util.StringUtils;
 41  
 
 42  
 /**
 43  
  * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
 44  
  * @version $Id: CvsExeScmProvider.java 1134851 2011-06-12 01:24:05Z godin $
 45  
  * @plexus.component role="org.apache.maven.scm.provider.ScmProvider" role-hint="cvs_native"
 46  
  */
 47  7
 public class CvsExeScmProvider
 48  
     extends AbstractCvsScmProvider
 49  
 {
 50  
     /** sserver transport method */
 51  
     public static final String TRANSPORT_SSERVER = "sserver";
 52  
 
 53  
     /** {@inheritDoc} */
 54  
     protected Command getAddCommand()
 55  
     {
 56  0
         return new CvsExeAddCommand();
 57  
     }
 58  
 
 59  
     /** {@inheritDoc} */
 60  
     protected Command getBranchCommand()
 61  
     {
 62  0
         return new CvsExeBranchCommand();
 63  
     }
 64  
 
 65  
     /** {@inheritDoc} */
 66  
     protected Command getBlameCommand()
 67  
     {
 68  0
         return new CvsExeBlameCommand();
 69  
     }
 70  
 
 71  
     /** {@inheritDoc} */
 72  
     protected Command getChangeLogCommand()
 73  
     {
 74  3
         return new CvsExeChangeLogCommand();
 75  
     }
 76  
 
 77  
     /** {@inheritDoc} */
 78  
     protected Command getCheckInCommand()
 79  
     {
 80  0
         return new CvsExeCheckInCommand();
 81  
     }
 82  
 
 83  
     /** {@inheritDoc} */
 84  
     protected Command getCheckOutCommand()
 85  
     {
 86  2
         return new CvsExeCheckOutCommand();
 87  
     }
 88  
 
 89  
     /** {@inheritDoc} */
 90  
     protected Command getDiffCommand()
 91  
     {
 92  0
         return new CvsExeDiffCommand();
 93  
     }
 94  
 
 95  
     /** {@inheritDoc} */
 96  
     protected Command getExportCommand()
 97  
     {
 98  0
         return new CvsExeExportCommand();
 99  
     }
 100  
 
 101  
     /** {@inheritDoc} */
 102  
     protected Command getListCommand()
 103  
     {
 104  0
         return new CvsExeListCommand();
 105  
     }
 106  
 
 107  
     /** {@inheritDoc} */
 108  
     protected Command getLoginCommand()
 109  
     {
 110  7
         return new CvsLoginCommand();
 111  
     }
 112  
 
 113  
     /** {@inheritDoc} */
 114  
     protected Command getRemoveCommand()
 115  
     {
 116  0
         return new CvsExeRemoveCommand();
 117  
     }
 118  
 
 119  
     /** {@inheritDoc} */
 120  
     protected Command getStatusCommand()
 121  
     {
 122  0
         return new CvsExeStatusCommand();
 123  
     }
 124  
 
 125  
     /** {@inheritDoc} */
 126  
     protected Command getTagCommand()
 127  
     {
 128  0
         return new CvsExeTagCommand();
 129  
     }
 130  
 
 131  
     /** {@inheritDoc} */
 132  
     protected Command getUpdateCommand()
 133  
     {
 134  2
         return new CvsExeUpdateCommand();
 135  
     }
 136  
     
 137  
     /** {@inheritDoc} */
 138  
     protected Command getMkdirCommand()
 139  
     {
 140  0
         return new CvsExeMkdirCommand();
 141  
     }    
 142  
 
 143  
     /** {@inheritDoc} */
 144  
     protected ScmUrlParserResult parseScmUrl( String scmSpecificUrl, char delimiter )
 145  
     {
 146  13
         ScmUrlParserResult result = super.parseScmUrl( scmSpecificUrl, delimiter );
 147  13
         if ( result.getMessages().isEmpty() )
 148  
         {
 149  11
             return result;
 150  
         }
 151  
 
 152  2
         result.resetMessages();
 153  
 
 154  2
         String[] tokens = StringUtils.split( scmSpecificUrl, Character.toString( delimiter ) );
 155  
 
 156  
         String cvsroot;
 157  
 
 158  2
         String transport = tokens[0];
 159  
 
 160  
         // support sserver
 161  2
         if ( transport.equalsIgnoreCase( TRANSPORT_SSERVER ) )
 162  
         {
 163  1
             if ( tokens.length < 4 || tokens.length > 5 && transport.equalsIgnoreCase( TRANSPORT_SSERVER ) )
 164  
             {
 165  0
                 result.getMessages().add( "The connection string contains too few tokens." );
 166  
 
 167  0
                 return result;
 168  
             }
 169  
 
 170  
             //create the cvsroot as the remote cvsroot
 171  1
             if ( tokens.length == 4 )
 172  
             {
 173  1
                 cvsroot = ":" + transport + ":" + tokens[1] + ":" + tokens[2];
 174  
             }
 175  
             else
 176  
             {
 177  0
                 cvsroot = ":" + transport + ":" + tokens[1] + ":" + tokens[2] + ":" + tokens[3];
 178  
             }
 179  
         }
 180  
         else
 181  
         {
 182  1
             result.getMessages().add( "Unknown transport: " + transport );
 183  
 
 184  1
             return result;
 185  
         }
 186  
 
 187  1
         String user = null;
 188  
 
 189  1
         String password = null;
 190  
 
 191  1
         String host = null;
 192  
 
 193  1
         String path = null;
 194  
 
 195  1
         String module = null;
 196  
 
 197  1
         int port = -1;
 198  
 
 199  1
         if ( transport.equalsIgnoreCase( TRANSPORT_SSERVER ) )
 200  
         {
 201  
             //sspi:[username@]host:[port]path:module
 202  1
             String userhost = tokens[1];
 203  
 
 204  1
             int index = userhost.indexOf( '@' );
 205  
 
 206  1
             if ( index == -1 )
 207  
             {
 208  1
                 user = "";
 209  
 
 210  1
                 host = userhost;
 211  
             }
 212  
             else
 213  
             {
 214  0
                 user = userhost.substring( 0, index );
 215  
 
 216  0
                 host = userhost.substring( index + 1 );
 217  
             }
 218  
 
 219  
             // no port specified
 220  1
             if ( tokens.length == 4 )
 221  
             {
 222  1
                 path = tokens[2];
 223  1
                 module = tokens[3];
 224  
             }
 225  
             else
 226  
             {
 227  
                 // getting port
 228  
                 try
 229  
                 {
 230  0
                     port = new Integer( tokens[2] ).intValue();
 231  0
                     path = tokens[3];
 232  0
                     module = tokens[4];
 233  
                 }
 234  0
                 catch ( Exception e )
 235  
                 {
 236  
                     //incorrect
 237  0
                     result.getMessages().add( "Your scm url is invalid, could not get port value." );
 238  
 
 239  0
                     return result;
 240  0
                 }
 241  
             }
 242  
 
 243  
             // cvsroot format is :sspi:host:path
 244  1
             cvsroot = ":" + transport + ":" + host + ":";
 245  
 
 246  1
             if ( port != -1 )
 247  
             {
 248  0
                 cvsroot += port;
 249  
             }
 250  
 
 251  1
             cvsroot += path;
 252  
         }
 253  
 
 254  1
         if ( port == -1 )
 255  
         {
 256  1
             result.setRepository( new CvsScmProviderRepository( cvsroot, transport, user, password, host, path,
 257  
                                                                 module ) );
 258  
         }
 259  
         else
 260  
         {
 261  0
             result.setRepository( new CvsScmProviderRepository( cvsroot, transport, user, password, host, port,
 262  
                                                                 path, module ) );
 263  
         }
 264  
 
 265  1
         return result;
 266  
     }
 267  
 }