Java URI Normalize normalizeGitRepoLocation(URI location)

Here you can find the source of normalizeGitRepoLocation(URI location)

Description

Normalizes a git repository location so that it never ends with ".git".

License

Open Source License

Declaration

public static URI normalizeGitRepoLocation(URI location) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014 IBM Corporation and others 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * /*from ww w. ja v a 2 s .c o m*/
 * Contributors:
 * IBM Corporation - initial API and implementation
 *******************************************************************************/

import java.net.URI;
import java.net.URISyntaxException;

public class Main {
    /**
     * Normalizes a git repository location so that it never ends with ".git".
     */
    public static URI normalizeGitRepoLocation(URI location) {
        final String locationString = location.toString();
        if (locationString.endsWith("/")) { //$NON-NLS-1$
            try {
                return new URI(locationString.substring(0, locationString.lastIndexOf("/"))); //$NON-NLS-1$
            } catch (URISyntaxException e) {
                //keep original location
            }
        }
        if (locationString.endsWith(".git")) { //$NON-NLS-1$
            try {
                return new URI(locationString.substring(0, locationString.lastIndexOf(".git"))); //$NON-NLS-1$
            } catch (URISyntaxException e) {
                //keep original location
            }
        }
        return location;
    }
}

Related

  1. normalize(URI input)
  2. normalize(URI location)
  3. normalize(URI uri)
  4. normalizedSetCookiePath(final String path, final URI originUri)
  5. normalizedUri(URI uri)
  6. normalizeLink(String link, URI parent, boolean removeParams)
  7. normalizeURI(final URI uri)
  8. normalizeURI(String uri)
  9. normalizeURIPath(String uri)