Here you can find the source of relativizePath(IPath path, IPath basePath, boolean strict)
private static IPath relativizePath(IPath path, IPath basePath, boolean strict)
//package com.java2s; /*/* w ww. j a v a 2 s . com*/ * Copyright 2016 Google 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. */ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; public class Main { /** * Returns the relative path of the original <code>path</code> with respect to the <code>basePath</code> if they share * the same prefix path, otherwise <code>path</code> is returned unchanged. If <code>path</code> is <code>null</code>, * <code>basePath</code> is returned. If <code>basePath</code> is <code>null</code>, <code>path</code> is returned. */ public static IPath relativizePath(IPath path, IPath basePath) { return relativizePath(path, basePath, false); } private static IPath relativizePath(IPath path, IPath basePath, boolean strict) { if (path == null) { return basePath; } if (basePath == null) { return path; } java.nio.file.Path base = basePath.toFile().toPath() .toAbsolutePath(); java.nio.file.Path child = path.toFile().toPath().toAbsolutePath(); if (child.startsWith(base)) { return new Path(base.relativize(child).toString()); } else if (strict) { return null; } else { return path; } } }