View Javadoc
1   package org.apache.maven.scm.provider.svn;
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.codehaus.plexus.util.StringUtils;
23  
24  /**
25   * Command utilities for svn commands.
26   *
27   * @author <a href="mailto:jerome@coffeebreaks.org">Jerome Lacoste</a>
28   *
29   */
30  public final class SvnCommandUtils
31  {
32  
33      private SvnCommandUtils()
34      {
35      }
36  
37      /**
38       * Add or overrides the username into a url with a svn+ssh scheme.
39       * <p/>
40       * Svn 1.3.1 doesn't use the username information specified by --username when the url
41       * uses the svn+ssh scheme. This allows to fix it. See MRELEASE-35.
42       * </p>
43       * Convert file url which derived from windows file path to unix path.
44       * </p>
45       * @param url      the url, not <code>null</code>
46       * @param username the username, may be <code>null</code>
47       * @return the fixed url
48       * @throws NullPointerException if url is <code>null</code>
49       */
50      public static String fixUrl( String url, String username )
51      {
52          if ( !StringUtils.isEmpty( username ) && url.startsWith( "svn+ssh://" ) )
53          {
54              // is there a username to override ? If so we cut after
55              int idx = url.indexOf( '@' );
56              int cutIdx = idx < 0 ? "svn+ssh://".length() : idx + 1;
57              url = "svn+ssh://" + username + "@" + url.substring( cutIdx );
58          }
59          else if ( url.startsWith( "file://" ) )
60          {
61              //some svn commands does not understand windows path separator in file URL derived from windows file path
62              url = url.replace( '\\', '/' );
63          }        
64          
65          return url;
66      }
67  }