blob: b8a037911d5ea4d9c810d9f7468435c8e7300954 [file] [log] [blame]
/*
* Copyright 2012-present Facebook, Inc.
*
* 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 com.facebook.buck.util;
import com.google.common.base.Preconditions;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
public final class MorePaths {
// Utility class: do not instantiate.
private MorePaths() {}
public static Path newPathInstance(String path) {
return separatorsToUnix(path);
}
public static Path newPathInstance(File file) {
return separatorsToUnix(file.getPath());
}
/**
* @return The path using UNIX path separators.
*/
public static Path separatorsToUnix(String path) {
return Paths.get(path.replace(File.separator, "/")).normalize();
}
/**
* @return The path using UNIX path separators.
*/
public static Path separatorsToUnix(Path path) {
return separatorsToUnix(path.toString());
}
/**
* @param toMakeAbsolute The {@link Path} to act upon.
* @return The Path, made absolute and normalized.
*/
public static Path absolutify(Path toMakeAbsolute) {
return Preconditions.checkNotNull(toMakeAbsolute).toAbsolutePath().normalize();
}
}