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 * Add or overrides the username into a url with a svn+ssh scheme. 38 * <p/> 39 * Svn 1.3.1 doesn't use the username information specified by --username when the url 40 * uses the svn+ssh scheme. This allows to fix it. See MRELEASE-35. 41 * </p> 42 * Convert file url which derived from windows file path to unix path. 43 * </p> 44 * @param url the url, not <code>null</code> 45 * @param username the username, may be <code>null</code> 46 * @return the fixed url 47 * @throws NullPointerException if url is <code>null</code> 48 */ 49 public static String fixUrl( String url, String username ) 50 { 51 if ( !StringUtils.isEmpty( username ) && url.startsWith( "svn+ssh://" ) ) 52 { 53 // is there a username to override ? If so we cut after 54 int idx = url.indexOf( '@' ); 55 int cutIdx = idx < 0 ? "svn+ssh://".length() : idx + 1; 56 url = "svn+ssh://" + username + "@" + url.substring( cutIdx ); 57 } 58 else if ( url.startsWith( "file://" ) ) 59 { 60 //some svn commands does not understand windows path separator in file URL derived from windows file path 61 url = url.replace( '\\', '/' ); 62 } 63 64 return url; 65 } 66 }