本文整理汇总了Java中com.intellij.openapi.util.io.FileUtil.getRelativePath方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtil.getRelativePath方法的具体用法?Java FileUtil.getRelativePath怎么用?Java FileUtil.getRelativePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.util.io.FileUtil
的用法示例。
在下文中一共展示了FileUtil.getRelativePath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: expand
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
@Override
public String expand(final DataContext dataContext) {
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (project == null) {
return null;
}
VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
if (file == null) {
return null;
}
final VirtualFile sourceRoot = ProjectRootManager.getInstance(project).getFileIndex().getSourceRootForFile(file);
if (sourceRoot == null) {
return null;
}
return FileUtil.getRelativePath(getIOFile(sourceRoot), getIOFile(file));
}
示例2: getDownloadFilesMessage
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private String getDownloadFilesMessage() {
final LibraryDownloadSettings downloadSettings = mySettings.getDownloadSettings();
if (downloadSettings == null) return "";
final String downloadPath = downloadSettings.getDirectoryForDownloadedLibrariesPath();
final String basePath = mySettings.getBaseDirectoryPath();
String path;
if (!StringUtil.isEmpty(basePath) && FileUtil.startsWith(downloadPath, basePath)) {
path = FileUtil.getRelativePath(basePath, downloadPath, '/');
}
else {
path = PathUtil.getFileName(downloadPath);
}
return MessageFormat.format("{0} {0, choice, 1#JAR|2#JARs} will be downloaded into <b>{1}</b> directory<br>" +
"{2} library <b>{3}</b> will be created",
downloadSettings.getSelectedDownloads().size(),
path,
downloadSettings.getLibraryLevel(),
downloadSettings.getLibraryName());
}
示例3: getPackageFromDirectory
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
/**
* Calculate the package name from the given target directory. Returns the package name or null if no package name could
* be calculated.
*/
@Nullable
public static String getPackageFromDirectory(@NotNull File directory, @NotNull SourceProvider sourceProvider,
@NotNull Module module, @NotNull TemplateWizardState wizardState) {
File javaSourceRoot;
File javaDir = findSrcDirectory(sourceProvider);
if (javaDir == null) {
javaSourceRoot = new File(AndroidRootUtil.getModuleDirPath(module),
FileUtil.toSystemDependentName(wizardState.getString(ATTR_SRC_DIR)));
}
else {
javaSourceRoot = new File(javaDir.getPath());
}
File javaSourcePackageRoot = new File(directory.getPath());
if (!FileUtil.isAncestor(javaSourceRoot, javaSourcePackageRoot, true)) {
return null;
}
String relativePath = FileUtil.getRelativePath(javaSourceRoot, javaSourcePackageRoot);
String packageName = relativePath != null ? FileUtil.toSystemIndependentName(relativePath).replace('/', '.') : null;
if (packageName == null || !AndroidUtils.isValidJavaPackageName(packageName)) {
return null;
}
return packageName;
}
示例4: pathRelativeToTask
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public static String pathRelativeToTask(VirtualFile file) {
VirtualFile taskDir = getTaskDir(file);
if (taskDir == null) return file.getName();
VirtualFile srcDir = taskDir.findChild(EduNames.SRC);
if (srcDir != null) {
taskDir = srcDir;
}
return FileUtil.getRelativePath(taskDir.getPath(), file.getPath(), '/');
}
示例5: fileCreated
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
@Override
public void fileCreated(@NotNull VirtualFileEvent event) {
if (myProject.isDisposed()) return;
final VirtualFile createdFile = event.getFile();
final VirtualFile taskDir = StudyUtils.getTaskDir(createdFile);
final Course course = StudyTaskManager.getInstance(myProject).getCourse();
if (course == null || !EduNames.STUDY.equals(course.getCourseMode())) {
return;
}
if (taskDir != null && taskDir.getName().contains(EduNames.TASK)) {
int taskIndex = EduUtils.getIndex(taskDir.getName(), EduNames.TASK);
final VirtualFile lessonDir = taskDir.getParent();
if (lessonDir != null && lessonDir.getName().contains(EduNames.LESSON)) {
int lessonIndex = EduUtils.getIndex(lessonDir.getName(), EduNames.LESSON);
List<Lesson> lessons = course.getLessons();
if (StudyUtils.indexIsValid(lessonIndex, lessons)) {
final Lesson lesson = lessons.get(lessonIndex);
final List<Task> tasks = lesson.getTaskList();
if (StudyUtils.indexIsValid(taskIndex, tasks)) {
final Task task = tasks.get(taskIndex);
final TaskFile taskFile = new TaskFile();
taskFile.initTaskFile(task, false);
taskFile.setUserCreated(true);
final String name = FileUtil.getRelativePath(taskDir.getPath(), createdFile.getPath(), '/');
taskFile.name = name;
//TODO: put to other steps as well
task.getTaskFiles().put(name, taskFile);
}
}
}
}
}
示例6: toRelativePath
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
@Nullable
private String toRelativePath(String absPath) {
absPath = FileUtil.toSystemIndependentName(absPath);
String moduleDirPath = AndroidRootUtil.getModuleDirPath(myContext.getModule());
if (moduleDirPath != null) {
moduleDirPath = FileUtil.toSystemIndependentName(moduleDirPath);
return FileUtil.getRelativePath(moduleDirPath, absPath, '/');
}
return null;
}
示例7: copyFromRoot
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public void copyFromRoot(String filePath,
int rootIndex, String outputPath,
CompileContext context, BuildOutputConsumer outputConsumer,
ArtifactOutputToSourceMapping outSrcMapping) throws IOException, ProjectBuildException {
final File file = new File(filePath);
if (!file.exists()) return;
String targetPath;
if (!FileUtil.filesEqual(file, getRootFile())) {
final String relativePath = FileUtil.getRelativePath(FileUtil.toSystemIndependentName(getRootFile().getPath()), filePath, '/');
if (relativePath == null || relativePath.startsWith("..")) {
throw new ProjectBuildException(new AssertionError(filePath + " is not under " + getRootFile().getPath()));
}
targetPath = JpsArtifactPathUtil.appendToPath(outputPath, relativePath);
}
else {
targetPath = outputPath;
}
final File targetFile = new File(targetPath);
if (FileUtil.filesEqual(file, targetFile)) {
//do not process file if should be copied to itself. Otherwise the file will be included to source-to-output mapping and will be deleted by rebuild
return;
}
if (outSrcMapping.getState(targetPath) == null) {
ProjectBuilderLogger logger = context.getLoggingManager().getProjectBuilderLogger();
if (logger.isEnabled()) {
logger.logCompiledFiles(Collections.singletonList(file), IncArtifactBuilder.BUILDER_NAME, "Copying file:");
}
myCopyingHandler.copyFile(file, targetFile, context);
outputConsumer.registerOutputFile(targetFile, Collections.singletonList(filePath));
}
else if (LOG.isDebugEnabled()) {
LOG.debug("Target path " + targetPath + " is already registered so " + filePath + " won't be copied");
}
outSrcMapping.appendData(targetPath, rootIndex, filePath);
}
示例8: setPathsToDefault
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
public static void setPathsToDefault(MavenProject mavenProject, Module module, AndroidFacetConfiguration configuration) {
String moduleDirPath = AndroidRootUtil.getModuleDirPath(module);
String genSources = FileUtil.toSystemIndependentName(mavenProject.getGeneratedSourcesDirectory(false));
if (moduleDirPath != null) {
final String genRelativePath = FileUtil.getRelativePath(moduleDirPath, genSources, '/');
if (genRelativePath != null) {
configuration.getState().GEN_FOLDER_RELATIVE_PATH_APT = '/' + genRelativePath + "/r";
configuration.getState().GEN_FOLDER_RELATIVE_PATH_AIDL = '/' + genRelativePath + "/aidl";
}
}
}
示例9: assertRelativePaths
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private static void assertRelativePaths(File[] baseDirs, Collection<File> files, String[] expected) {
List<String> relativePaths = new ArrayList<String>();
for (File file : files) {
String path = file.getAbsolutePath();
for (File baseDir : baseDirs) {
if (baseDir != null && FileUtil.isAncestor(baseDir, file, false)) {
path = FileUtil.getRelativePath(baseDir, file);
break;
}
}
relativePaths.add(FileUtil.toSystemIndependentName(path));
}
UsefulTestCase.assertSameElements(relativePaths, expected);
}
示例10: getJavaPath
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
@Nullable
private static String getJavaPath(File ioModuleDir, @Nullable File javaDir) {
String javaPath = null;
if (javaDir != null) {
javaPath = FileUtil.getRelativePath(ioModuleDir, javaDir);
if (javaPath != null) {
javaPath = FileUtil.toSystemIndependentName(javaPath);
}
}
return javaPath;
}
示例11: getPackage
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
@Nullable
public PsiPackage getPackage(PsiDirectory dir) {
final VirtualFile file = dir.getVirtualFile();
for (VirtualFile root : myClasspath) {
if (VfsUtilCore.isAncestor(root, file, false)) {
String relativePath = FileUtil.getRelativePath(root.getPath(), file.getPath(), '/');
if (relativePath == null) continue;
return new PsiPackageImpl(myPsiManager, relativePath.replace('/', '.'));
}
}
return null;
}
示例12: getUpdatedFiles
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
@NotNull
private Collection<String> getUpdatedFiles(@NotNull FileGroup group) {
Function<String, String> getRelative = new Function<String, String>() {
@Override
public String fun(String path) {
return FileUtil.getRelativePath(new File(myProjectPath), new File(path));
}
};
Collection<String> result = ContainerUtil.newArrayList();
result.addAll(ContainerUtil.map(group.getFiles(), getRelative));
for (FileGroup child : group.getChildren()) {
result.addAll(getUpdatedFiles(child));
}
return result;
}
示例13: getRelativePath
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private String getRelativePath(final String basePath, final String secondPath) {
final String baseModified = FileUtil.toSystemIndependentName(basePath);
final String secondModified = FileUtil.toSystemIndependentName(secondPath);
final String relPath = FileUtil.getRelativePath(baseModified, secondModified, '/', myIsCaseSensitive);
if (relPath == null) return secondModified;
return relPath;
}
示例14: toReadable
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
private String toReadable(List<TestCommit> commits) {
int maxSubjectLength = findMaxLength(commits, new Function<TestCommit, String>() {
@Override
public String fun(TestCommit revision) {
return revision.getCommitMessage();
}
});
StringBuilder sb = new StringBuilder();
for (TestCommit commit : commits) {
String relPath = FileUtil.getRelativePath(new File(myProjectPath), new File(commit.myPath));
sb.append(String.format("%s %-" + maxSubjectLength + "s %s%n", getShortHash(commit.getHash()), commit.getCommitMessage(), relPath));
}
return sb.toString();
}
示例15: gdbPathToWorkspaceRelativePath
import com.intellij.openapi.util.io.FileUtil; //导入方法依赖的package包/类
/**
* Heuristic to try to handle the case where the file returned by gdb uses the canonical path but
* the user imported their project using a non-canonical path. For example, this handles the case
* where the user keeps their git5 repos on a different mount and accesses them via a symlink from
* their home directory.
*
* @param workspaceDirectory workspace root, as it was imported into CLion
* @param file file returned by GDB
* @return The relative path for {@param file} as it was imported into CLion
*/
private String gdbPathToWorkspaceRelativePath(File workspaceDirectory, File file) {
try {
File canonicalWorkspaceDirectory = workspaceDirectory.getCanonicalFile();
File canonicalFile = file.getCanonicalFile();
String relativeCanonicalPath =
FileUtil.getRelativePath(canonicalWorkspaceDirectory, canonicalFile);
if (relativeCanonicalPath != null) {
return relativeCanonicalPath;
}
} catch (IOException e) {
LOG.info(e);
}
return file.getPath();
}