當前位置: 首頁>>代碼示例>>Java>>正文


Java FileUtil.getRelativePath方法代碼示例

本文整理匯總了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));
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:17,代碼來源:FilePathRelativeToSourcepathMacro.java

示例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());
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:21,代碼來源:LibraryOptionsPanel.java

示例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;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:30,代碼來源:NewTemplateObjectWizard.java

示例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(), '/');
}
 
開發者ID:medvector,項目名稱:educational-plugin,代碼行數:10,代碼來源:StudyUtils.java

示例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);
        }
      }
    }
  }
}
 
開發者ID:medvector,項目名稱:educational-plugin,代碼行數:33,代碼來源:StudyProjectComponent.java

示例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;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:11,代碼來源:AndroidFacetEditorTab.java

示例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);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:38,代碼來源:FileBasedArtifactRootDescriptor.java

示例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";
    }
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:14,代碼來源:AndroidMavenProviderImpl.java

示例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);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:15,代碼來源:TestProjectBuilderLogger.java

示例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;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:12,代碼來源:AddAndroidActivityPath.java

示例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;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:13,代碼來源:CoreJavaFileManager.java

示例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;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:16,代碼來源:GitPushOperationSingleRepoTest.java

示例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;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:9,代碼來源:TextPatchBuilder.java

示例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();
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:15,代碼來源:GitHistoryUtilsTest.java

示例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();
}
 
開發者ID:bazelbuild,項目名稱:intellij,代碼行數:25,代碼來源:BlazeGDBDriverConfiguration.java


注:本文中的com.intellij.openapi.util.io.FileUtil.getRelativePath方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。