Java Code Examples for com.intellij.openapi.util.io.FileUtil#pathsEqual()

The following examples show how to use com.intellij.openapi.util.io.FileUtil#pathsEqual() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProjectUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static boolean isSameProject(@Nullable String projectFilePath, @Nonnull Project project) {
  if (projectFilePath == null) return false;

  IProjectStore projectStore = ((ProjectEx)project).getStateStore();
  String existingBaseDirPath = projectStore.getProjectBasePath();
  if (existingBaseDirPath == null) {
    // could be null if not yet initialized
    return false;
  }

  File projectFile = new File(projectFilePath);
  if (projectFile.isDirectory()) {
    return FileUtil.pathsEqual(projectFilePath, existingBaseDirPath);
  }


  File parent = projectFile.getParentFile();
  if (parent.getName().equals(Project.DIRECTORY_STORE_FOLDER)) {
    parent = parent.getParentFile();
    return parent != null && FileUtil.pathsEqual(parent.getPath(), existingBaseDirPath);
  }
  return false;
}
 
Example 2
Source File: VcsUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static List<VcsDirectoryMapping> addMapping(@Nonnull List<VcsDirectoryMapping> existingMappings,
                                                   @Nonnull String path,
                                                   @Nonnull String vcs) {
  List<VcsDirectoryMapping> mappings = new ArrayList<>(existingMappings);
  for (Iterator<VcsDirectoryMapping> iterator = mappings.iterator(); iterator.hasNext(); ) {
    VcsDirectoryMapping mapping = iterator.next();
    if (mapping.isDefaultMapping() && StringUtil.isEmptyOrSpaces(mapping.getVcs())) {
      LOG.debug("Removing <Project> -> <None> mapping");
      iterator.remove();
    }
    else if (FileUtil.pathsEqual(mapping.getDirectory(), path)) {
      if (!StringUtil.isEmptyOrSpaces(mapping.getVcs())) {
        LOG.warn("Substituting existing mapping [" + path + "] -> [" + mapping.getVcs() + "] with [" + vcs + "]");
      }
      else {
        LOG.debug("Removing [" + path + "] -> <None> mapping");
      }
      iterator.remove();
    }
  }
  mappings.add(new VcsDirectoryMapping(path, vcs));
  return mappings;
}
 
Example 3
Source File: ItemPath.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
public boolean equals(final Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    final ItemPath itemPath = (ItemPath) o;

    return FileUtil.pathsEqual(getLocalPath().getPath(), itemPath.getLocalPath().getPath());
}
 
Example 4
Source File: BashRunConfigProducer.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isConfigurationFromContext(BashRunConfiguration configuration, ConfigurationContext context) {
    Location location = context.getLocation();
    if (location == null) {
        return false;
    }

    //fixme file checks needs to check the properties

    VirtualFile file = location.getVirtualFile();
    return file != null && FileUtil.pathsEqual(file.getPath(), configuration.getScriptName());
}
 
Example 5
Source File: Review.java    From Crucible4IDEA with MIT License 5 votes vote down vote up
@Nullable
public String getIdByPath(@NotNull final String path, Project project) {
  final Map<String,VirtualFile> hash = CrucibleManager.getInstance(project).getRepoHash();

  for (ReviewItem item : myItems) {
    final String repo = item.getRepo();
    final String root = hash.containsKey(repo) ? hash.get(repo).getPath() : project.getBasePath();
    String relativePath = FileUtil.getRelativePath(new File(Objects.requireNonNull(root)), new File(path));
    if (FileUtil.pathsEqual(relativePath, item.getPath())) {
      return item.getId();
    }
  }
  return null;
}
 
Example 6
Source File: ModuleManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private ModuleEx getModuleByDirUrl(@Nonnull String dirUrl) {
  for (Module module : myModules) {
    if (FileUtil.pathsEqual(dirUrl, module.getModuleDirUrl())) {
      return (ModuleEx)module;
    }
  }
  return null;
}
 
Example 7
Source File: ModuleManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private Module removeModuleByDirUrl(@Nonnull String dirUrl) {
  Module toRemove = null;
  for (Module module : myModules) {
    if (FileUtil.pathsEqual(dirUrl, module.getModuleDirUrl())) {
      toRemove = module;
    }
  }
  myModules.remove(toRemove);
  return toRemove;
}
 
Example 8
Source File: UsefulTestCase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void tearDown() throws Exception {
  try {
    Disposer.dispose(myTestRootDisposable);
    cleanupSwingDataStructures();
  }
  finally {
    if (shouldContainTempFiles()) {
      FileUtil.resetCanonicalTempPathCache(ORIGINAL_TEMP_DIR);
      if (ourPathToKeep != null && FileUtil.isAncestor(myTempDir, ourPathToKeep, false)) {
        File[] files = new File(myTempDir).listFiles();
        if (files != null) {
          for (File file : files) {
            if (!FileUtil.pathsEqual(file.getPath(), ourPathToKeep)) {
              FileUtil.delete(file);
            }
          }
        }
      }
      else {
        FileUtil.delete(new File(myTempDir));
      }
    }
  }

  UIUtil.removeLeakingAppleListeners();
  super.tearDown();
}
 
Example 9
Source File: TranslationSourceFileInfo.java    From consulo with Apache License 2.0 5 votes vote down vote up
public boolean isAssociated(int projectId, String outputPath) {
  if (myProjectToOutputPathMap != null) {
    final Object val = myProjectToOutputPathMap.get(projectId);
    if (val instanceof Integer) {
      VirtualFile fileById = VirtualFileManager.getInstance().findFileById((Integer)val);
      return FileUtil.pathsEqual(outputPath, fileById != null ? fileById.getPath() : "");
    }
    if (val instanceof TIntHashSet) {
      VirtualFile vf = LocalFileSystem.getInstance().findFileByPath(outputPath);
      int _outputPath = vf == null ? -1 : FileBasedIndex.getFileId(vf);
      return ((TIntHashSet)val).contains(_outputPath);
    }
  }
  return false;
}
 
Example 10
Source File: VirtualFilePointerContainerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean removeJarDirectory(@Nonnull String directoryUrl) {
  dropCaches();
  Predicate<VirtualFilePointer> filter = ptr -> FileUtil.pathsEqual(ptr.getUrl(), directoryUrl);
  boolean removed0 = myList.removeIf(filter);
  boolean removed1 = myJarDirectories.removeIf(filter);
  boolean removed2 = myJarRecursiveDirectories.removeIf(filter);
  return removed0 || removed1 || removed2;
}
 
Example 11
Source File: RootSettingsUtil.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
@NotNull
public static P4VcsRootSettings getFixedRootSettings(
        @NotNull Project project,
        @NotNull VcsDirectoryMapping mapping,
        @NotNull VirtualFile rootDir) {
    // See #209 - This mapping, if done wrong, will cause the plugin
    // to not associate the roots to the configuration correctly.

    VcsRootSettings rawSettings = mapping.getRootSettings();
    P4VcsRootSettings retSettings = null;
    if (rawSettings instanceof P4VcsRootSettings) {
        retSettings = (P4VcsRootSettings) rawSettings;
    } else {
        LOG.warn("Encountered wrong root settings type in directory mapping: " +
                (rawSettings == null ? null : rawSettings.getClass()));
    }
    List<ConfigPart> parts = null;
    if (retSettings != null) {
        if (! FileUtil.pathsEqual(rootDir.getPath(), retSettings.getRootDir().getPath())) {
            LOG.info("Mapping has directory " + mapping.getDirectory() +
                    " which does not match P4 VCS settings dir " +
                    retSettings.getRootDir().getPath() + "; root dir " + rootDir);
            if (! retSettings.usesDefaultConfigParts()) {
                parts = retSettings.getConfigParts();
            }
            retSettings = null;
        }
    }
    if (retSettings == null) {
        // This shouldn't happen, but it does.  Instead, the mapping is supposed
        // to be created through the createEmptyVcsRootSettings() method.
        // That's reflected in the deprecation of setRootSettings.
        LOG.info("Encountered empty root settings in directory mapping.");
        if (LOG.isDebugEnabled()) {
            LOG.debug("Using root path " + rootDir);
        }
        retSettings = new P4VcsRootSettingsImpl(project, rootDir);
        if (parts != null && retSettings.usesDefaultConfigParts()) {
            retSettings.setConfigParts(parts);
        }
        mapping.setRootSettings(retSettings);
    }
    return retSettings;
}
 
Example 12
Source File: BasePathMacroManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected static boolean pathsEqual(@Nullable String path1, @javax.annotation.Nullable String path2) {
  return path1 != null && path2 != null &&
         FileUtil.pathsEqual(FileUtil.toSystemIndependentName(path1), FileUtil.toSystemIndependentName(path2));
}
 
Example 13
Source File: OneProjectItemCompileScope.java    From consulo with Apache License 2.0 4 votes vote down vote up
public boolean belongs(String url) {
  if (myFile.isDirectory()){
    return FileUtil.startsWith(url, myUrl);
  }
  return FileUtil.pathsEqual(url, myUrl);
}
 
Example 14
Source File: FilePath.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean equals(Object o) {
  if (this == o) return true;
  if (o == null || getClass() != o.getClass()) return false;
  return FileUtil.pathsEqual(myPath, ((FilePath)o).myPath);
}
 
Example 15
Source File: ChangesTreeList.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean seemsToBeMoved(Change change, VirtualFile toSelect) {
  ContentRevision afterRevision = change.getAfterRevision();
  if (afterRevision == null) return false;
  FilePath file = afterRevision.getFile();
  return FileUtil.pathsEqual(file.getPath(), toSelect.getPath());
}