Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright 2014-2015 Red Hat, Inc. and/or its affiliates
  * and other contributors as indicated by the @author tags.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.hawkular.build.license;
A utility to transform native java.io.File paths to the form expected by jGit - i.e. relative to git working tree root directory and delimited by '/'.

Author(s):
Peter Palaga
public class GitPathResolver {

    
The path separator expected by jGit.
    private static final char CANONICAL_PATH_SEPARATOR = '/';

    
The file path separator used by the current platform, usually java.io.File.separatorChar.
    private final char nativePathSeparator;

    
The native path to the root directory of the current git repository working tree.
    private final String repositoryRootDir;
    public GitPathResolver(String repositoryRootDir) {
        this(repositoryRootDir.);
    }

    
Default visibility for testing purposes.

Parameters:
repositoryRootDir
nativePathSeparator
    GitPathResolver(String repositoryRootDirchar nativePathSeparator) {
        super();
        this. = repositoryRootDir.charAt(repositoryRootDir.length() - 1) == nativePathSeparator ? repositoryRootDir
                : repositoryRootDir + nativePathSeparator;
        this. = nativePathSeparator;
    }

    
With default visibility to be testable.

Parameters:
absoluteNativePath
Returns:
    String relativize(String absoluteNativePath) {
        if (!absoluteNativePath.startsWith()) {
            throw new RuntimeException("Cannot relativize path '" + absoluteNativePath + "' to directory '"
                    +  + "'");
        }
        String result = absoluteNativePath.substring(.length());
        if ( != ) {
            result = result.replace();
        }
        return result;
    }

    
Return a string representing the supplied path path relative to git working tree root directory and delimited by '/'.

Parameters:
path the path to relativize
Returns:
the relativized path
    public String relativize(File path) {
        return relativize(path.getAbsolutePath());
    }
New to GrepCode? Check out our FAQ X