Coverage Report - org.apache.maven.scm.provider.tfs.TfsScmProvider
 
Classes in this File Line Coverage Branch Coverage Complexity
TfsScmProvider
0 %
0/67
0 %
0/18
1,75
 
 1  
 package org.apache.maven.scm.provider.tfs;
 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 java.net.URI;
 23  
 
 24  
 import org.apache.maven.scm.CommandParameters;
 25  
 import org.apache.maven.scm.ScmException;
 26  
 import org.apache.maven.scm.ScmFileSet;
 27  
 import org.apache.maven.scm.command.add.AddScmResult;
 28  
 import org.apache.maven.scm.command.blame.BlameScmResult;
 29  
 import org.apache.maven.scm.command.branch.BranchScmResult;
 30  
 import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
 31  
 import org.apache.maven.scm.command.checkin.CheckInScmResult;
 32  
 import org.apache.maven.scm.command.checkout.CheckOutScmResult;
 33  
 import org.apache.maven.scm.command.diff.DiffScmResult;
 34  
 import org.apache.maven.scm.command.edit.EditScmResult;
 35  
 import org.apache.maven.scm.command.export.ExportScmResult;
 36  
 import org.apache.maven.scm.command.list.ListScmResult;
 37  
 import org.apache.maven.scm.command.status.StatusScmResult;
 38  
 import org.apache.maven.scm.command.tag.TagScmResult;
 39  
 import org.apache.maven.scm.command.unedit.UnEditScmResult;
 40  
 import org.apache.maven.scm.command.update.UpdateScmResult;
 41  
 import org.apache.maven.scm.provider.AbstractScmProvider;
 42  
 import org.apache.maven.scm.provider.ScmProviderRepository;
 43  
 import org.apache.maven.scm.provider.tfs.command.TfsAddCommand;
 44  
 import org.apache.maven.scm.provider.tfs.command.TfsBranchCommand;
 45  
 import org.apache.maven.scm.provider.tfs.command.TfsChangeLogCommand;
 46  
 import org.apache.maven.scm.provider.tfs.command.TfsCheckInCommand;
 47  
 import org.apache.maven.scm.provider.tfs.command.TfsCheckOutCommand;
 48  
 import org.apache.maven.scm.provider.tfs.command.TfsEditCommand;
 49  
 import org.apache.maven.scm.provider.tfs.command.TfsListCommand;
 50  
 import org.apache.maven.scm.provider.tfs.command.TfsStatusCommand;
 51  
 import org.apache.maven.scm.provider.tfs.command.TfsTagCommand;
 52  
 import org.apache.maven.scm.provider.tfs.command.TfsUnEditCommand;
 53  
 import org.apache.maven.scm.provider.tfs.command.TfsUpdateCommand;
 54  
 import org.apache.maven.scm.provider.tfs.command.blame.TfsBlameCommand;
 55  
 import org.apache.maven.scm.repository.ScmRepositoryException;
 56  
 
 57  
 /**
 58  
  * @plexus.component role="org.apache.maven.scm.provider.ScmProvider" role-hint="tfs"
 59  
  */
 60  0
 public class TfsScmProvider
 61  
     extends AbstractScmProvider
 62  
 {
 63  
 
 64  
     public static final String TFS_URL_FORMAT =
 65  
         "[[domain\\]username[;password]@]http[s]://server_name[:port]:workspace:$/TeamProject/Path/To/Project";
 66  
 
 67  
     // ----------------------------------------------------------------------
 68  
     // ScmProvider Implementation
 69  
     // ----------------------------------------------------------------------
 70  
 
 71  
     public String getScmType()
 72  
     {
 73  0
         return "tfs";
 74  
     }
 75  
 
 76  
     public ScmProviderRepository makeProviderScmRepository( String scmUrl, char delimiter )
 77  
         throws ScmRepositoryException
 78  
     {
 79  
         // Look for the TFS URL after any '@' delmiter used to pass
 80  
         // usernames/password etc
 81  
         // We deliberately look for the last '@' character as username could
 82  
         // contain an '@' also.
 83  0
         int lastAtPos = scmUrl.lastIndexOf( '@' );
 84  0
         getLogger().info( "scmUrl - " + scmUrl );
 85  
 
 86  0
         String tfsUrl = ( lastAtPos < 0 ) ? scmUrl : scmUrl.substring( lastAtPos + 1 );
 87  0
         String usernamePassword = ( lastAtPos < 0 ) ? null : scmUrl.substring( 0, lastAtPos );
 88  
 
 89  
         // Look for TFS path after the end of the TFS URL
 90  0
         int tfsPathPos = tfsUrl.lastIndexOf( delimiter + "$/" );
 91  0
         String serverPath = "$/";
 92  0
         if ( tfsPathPos > 0 )
 93  
         {
 94  0
             serverPath = tfsUrl.substring( tfsPathPos + 1 );
 95  0
             tfsUrl = tfsUrl.substring( 0, tfsPathPos );
 96  
         }
 97  
 
 98  
         // Look for workspace ater the end of the TFS URL
 99  0
         int workspacePos = tfsUrl.lastIndexOf( delimiter );
 100  0
         String workspace = tfsUrl.substring( workspacePos + 1 );
 101  0
         tfsUrl = tfsUrl.substring( 0, workspacePos );
 102  
 
 103  
         try
 104  
         {
 105  
             // Use URI's validation to determine if valid URI.
 106  0
             URI tfsUri = URI.create( tfsUrl );
 107  0
             String scheme = tfsUri.getScheme();
 108  0
             getLogger().info( "Scheme - " + scheme );
 109  0
             if ( scheme == null || !( scheme.equalsIgnoreCase( "http" ) || scheme.equalsIgnoreCase( "https" ) ) )
 110  
             {
 111  0
                 throw new ScmRepositoryException( "TFS Url \"" + tfsUrl + "\" is not a valid URL. "
 112  
                     + "The TFS Url syntax is " + TFS_URL_FORMAT );
 113  
             }
 114  
         }
 115  0
         catch ( IllegalArgumentException e )
 116  
         {
 117  0
             throw new ScmRepositoryException( "TFS Url \"" + tfsUrl + "\" is not a valid URL. The TFS Url syntax is "
 118  
                 + TFS_URL_FORMAT );
 119  0
         }
 120  
 
 121  0
         String username = null;
 122  0
         String password = null;
 123  
 
 124  0
         if ( usernamePassword != null )
 125  
         {
 126  
             // Deliberately not using .split here in case password contains a
 127  
             // ';'
 128  0
             int delimPos = usernamePassword.indexOf( ';' );
 129  0
             username = ( delimPos < 0 ) ? usernamePassword : usernamePassword.substring( 0, delimPos );
 130  0
             password = ( delimPos < 0 ) ? null : usernamePassword.substring( delimPos + 1 );
 131  
         }
 132  
 
 133  0
         return new TfsScmProviderRepository( tfsUrl, username, password, serverPath, workspace );
 134  
     }
 135  
 
 136  
     protected ChangeLogScmResult changelog( ScmProviderRepository repository, ScmFileSet fileSet,
 137  
                                             CommandParameters parameters )
 138  
         throws ScmException
 139  
     {
 140  0
         TfsChangeLogCommand command = new TfsChangeLogCommand();
 141  0
         command.setLogger( getLogger() );
 142  0
         return (ChangeLogScmResult) command.execute( repository, fileSet, parameters );
 143  
     }
 144  
 
 145  
     protected CheckOutScmResult checkout( ScmProviderRepository repository, ScmFileSet fileSet,
 146  
                                           CommandParameters parameters )
 147  
         throws ScmException
 148  
     {
 149  0
         TfsCheckOutCommand command = new TfsCheckOutCommand();
 150  0
         command.setLogger( getLogger() );
 151  0
         return (CheckOutScmResult) command.execute( repository, fileSet, parameters );
 152  
     }
 153  
 
 154  
     protected EditScmResult edit( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
 155  
         throws ScmException
 156  
     {
 157  0
         TfsEditCommand command = new TfsEditCommand();
 158  0
         command.setLogger( getLogger() );
 159  0
         return (EditScmResult) command.execute( repository, fileSet, parameters );
 160  
     }
 161  
 
 162  
     protected UnEditScmResult unedit( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
 163  
         throws ScmException
 164  
     {
 165  0
         TfsUnEditCommand command = new TfsUnEditCommand();
 166  0
         command.setLogger( getLogger() );
 167  0
         return (UnEditScmResult) command.execute( repository, fileSet, parameters );
 168  
     }
 169  
 
 170  
     protected StatusScmResult status( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
 171  
         throws ScmException
 172  
     {
 173  0
         TfsStatusCommand command = new TfsStatusCommand();
 174  0
         command.setLogger( getLogger() );
 175  0
         return (StatusScmResult) command.execute( repository, fileSet, parameters );
 176  
     }
 177  
 
 178  
     protected UpdateScmResult update( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
 179  
         throws ScmException
 180  
     {
 181  0
         TfsUpdateCommand command = new TfsUpdateCommand();
 182  0
         command.setLogger( getLogger() );
 183  0
         return (UpdateScmResult) command.execute( repository, fileSet, parameters );
 184  
     }
 185  
 
 186  
     protected CheckInScmResult checkin( ScmProviderRepository repository, ScmFileSet fileSet,
 187  
                                         CommandParameters parameters )
 188  
         throws ScmException
 189  
     {
 190  0
         TfsCheckInCommand command = new TfsCheckInCommand();
 191  0
         command.setLogger( getLogger() );
 192  0
         return (CheckInScmResult) command.execute( repository, fileSet, parameters );
 193  
     }
 194  
 
 195  
     public AddScmResult add( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
 196  
         throws ScmException
 197  
     {
 198  0
         TfsAddCommand command = new TfsAddCommand();
 199  0
         command.setLogger( getLogger() );
 200  0
         return (AddScmResult) command.execute( repository, fileSet, parameters );
 201  
     }
 202  
 
 203  
     protected TagScmResult tag( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
 204  
         throws ScmException
 205  
     {
 206  0
         TfsTagCommand command = new TfsTagCommand();
 207  0
         command.setLogger( getLogger() );
 208  0
         return (TagScmResult) command.execute( repository, fileSet, parameters );
 209  
     }
 210  
 
 211  
     protected BranchScmResult branch( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
 212  
         throws ScmException
 213  
     {
 214  0
         TfsBranchCommand command = new TfsBranchCommand();
 215  0
         command.setLogger( getLogger() );
 216  0
         return (BranchScmResult) command.execute( repository, fileSet, parameters );
 217  
     }
 218  
 
 219  
     protected ListScmResult list( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
 220  
         throws ScmException
 221  
     {
 222  0
         TfsListCommand command = new TfsListCommand();
 223  0
         command.setLogger( getLogger() );
 224  0
         return (ListScmResult) command.execute( repository, fileSet, parameters );
 225  
     }
 226  
 
 227  
     protected BlameScmResult blame( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
 228  
         throws ScmException
 229  
     {
 230  0
         TfsBlameCommand command = new TfsBlameCommand();
 231  0
         command.setLogger( getLogger() );
 232  0
         return (BlameScmResult) command.execute( repository, fileSet, parameters );
 233  
     }
 234  
 
 235  
     protected DiffScmResult diff( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
 236  
         throws ScmException
 237  
     {
 238  
         // Because tf launches only external diffs
 239  0
         return super.diff( repository, fileSet, parameters );
 240  
     }
 241  
 
 242  
     protected ExportScmResult export( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
 243  
         throws ScmException
 244  
     {
 245  
         // Use checkout instead
 246  0
         return super.export( repository, fileSet, parameters );
 247  
     }
 248  
 
 249  
 }