001 package org.apache.maven.scm.provider.svn; 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.codehaus.plexus.util.StringUtils; 023 024 /** 025 * Command utilities for svn commands. 026 * 027 * @author <a href="mailto:jerome@coffeebreaks.org">Jerome Lacoste</a> 028 * @version $Id: SvnCommandUtils.java 1134992 2011-06-12 21:54:27Z godin $ 029 */ 030 public final class SvnCommandUtils 031 { 032 033 private SvnCommandUtils() { 034 } 035 036 /** 037 * Add or overrides the username into a url with a svn+ssh scheme. 038 * <p/> 039 * Svn 1.3.1 doesn't use the username information specified by --username when the url 040 * uses the svn+ssh scheme. This allows to fix it. See MRELEASE-35. 041 * </p> 042 * Convert file url which derived from windows file path to unix path. 043 * </p> 044 * @param url the url, not <code>null</code> 045 * @param username the username, may be <code>null</code> 046 * @return the fixed url 047 * @throws NullPointerException if url is <code>null</code> 048 */ 049 public static String fixUrl( String url, String username ) 050 { 051 if ( !StringUtils.isEmpty( username ) && url.startsWith( "svn+ssh://" ) ) 052 { 053 // is there a username to override ? If so we cut after 054 int idx = url.indexOf( '@' ); 055 int cutIdx = idx < 0 ? "svn+ssh://".length() : idx + 1; 056 url = "svn+ssh://" + username + "@" + url.substring( cutIdx ); 057 } 058 else if ( url.startsWith( "file://" ) ) 059 { 060 //some svn commands does not understand windows path separator in file URL derived from windows file path 061 url = url.replace( '\\', '/' ); 062 } 063 064 return url; 065 } 066 }