blob: 9d0d2a479143c7e21dc622cc39c50b8221f2d9be [file] [log] [blame]
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* 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.jetbrains.jps.incremental.artifacts.impl;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.util.text.StringUtilRt;
import org.jetbrains.annotations.NotNull;
import java.io.File;
/**
* @author nik
*/
public class JpsArtifactPathUtil {
//todo[nik] copied from DeploymentUtil
public static String trimForwardSlashes(@NotNull String path) {
while (path.length() != 0 && (path.charAt(0) == '/' || path.charAt(0) == File.separatorChar)) {
path = path.substring(1);
}
return path;
}
//todo[nik] copied from DeploymentUtil
public static String appendToPath(@NotNull String basePath, @NotNull String relativePath) {
final boolean endsWithSlash = StringUtilRt.endsWithChar(basePath, '/') || StringUtilRt.endsWithChar(basePath, '\\');
final boolean startsWithSlash = StringUtil.startsWithChar(relativePath, '/') || StringUtil.startsWithChar(relativePath, '\\');
String tail;
if (endsWithSlash && startsWithSlash) {
tail = trimForwardSlashes(relativePath);
}
else if (!endsWithSlash && !startsWithSlash && basePath.length() > 0 && relativePath.length() > 0) {
tail = "/" + relativePath;
}
else {
tail = relativePath;
}
return basePath + tail;
}
}