001package 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 022import 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 * 029 */ 030public final class SvnCommandUtils 031{ 032 033 private SvnCommandUtils() 034 { 035 } 036 037 /** 038 * Add or overrides the username into a url with a svn+ssh scheme. 039 * <p/> 040 * Svn 1.3.1 doesn't use the username information specified by --username when the url 041 * uses the svn+ssh scheme. This allows to fix it. See MRELEASE-35. 042 * </p> 043 * Convert file url which derived from windows file path to unix path. 044 * </p> 045 * @param url the url, not <code>null</code> 046 * @param username the username, may be <code>null</code> 047 * @return the fixed url 048 * @throws NullPointerException if url is <code>null</code> 049 */ 050 public static String fixUrl( String url, String username ) 051 { 052 if ( !StringUtils.isEmpty( username ) && url.startsWith( "svn+ssh://" ) ) 053 { 054 // is there a username to override ? If so we cut after 055 int idx = url.indexOf( '@' ); 056 int cutIdx = idx < 0 ? "svn+ssh://".length() : idx + 1; 057 url = "svn+ssh://" + username + "@" + url.substring( cutIdx ); 058 } 059 else if ( url.startsWith( "file://" ) ) 060 { 061 //some svn commands does not understand windows path separator in file URL derived from windows file path 062 url = url.replace( '\\', '/' ); 063 } 064 065 return url; 066 } 067}