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

The following examples show how to use com.intellij.openapi.util.io.FileUtil#filesEqual() . 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: PackageFileWorker.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void copyFile(String outputPath, List<CompositePackagingElement<?>> parents) throws IOException {
  if (parents.isEmpty()) {
    final String fullOutputPath = DeploymentUtil.appendToPath(outputPath, myRelativeOutputPath);
    File target = new File(fullOutputPath);
    if (FileUtil.filesEqual(myFile, target)) {
      LOG.debug("  skipping copying file to itself");
    }
    else {
      LOG.debug("  copying to " + fullOutputPath);
      FileUtil.copy(myFile, target);
    }
    return;
  }

  final CompositePackagingElement<?> element = parents.get(0);
  final String nextOutputPath = outputPath + "/" + element.getName();
  final List<CompositePackagingElement<?>> parentsTrail = parents.subList(1, parents.size());
  if (element instanceof ArchivePackagingElement) {
    packFile(nextOutputPath, "", parentsTrail);
  }
  else {
    copyFile(nextOutputPath, parentsTrail);
  }
}
 
Example 2
Source File: ChooseComponentsToExportDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean addToExistingListElement(ExportSettingsAction.ExportableItem component,
                                                Map<ExportSettingsAction.ExportableItem, ComponentElementProperties> componentToContainingListElement,
                                                MultiMap<File, ExportSettingsAction.ExportableItem> fileToComponents) {
  final File[] exportFiles = component.getExportFiles();
  File file = null;
  for (File exportFile : exportFiles) {
    Collection<ExportSettingsAction.ExportableItem> tiedComponents = fileToComponents.get(exportFile);

    for (ExportSettingsAction.ExportableItem tiedComponent : tiedComponents) {
      if (tiedComponent == component) continue;
      final ComponentElementProperties elementProperties = componentToContainingListElement.get(tiedComponent);
      if (elementProperties != null && !FileUtil.filesEqual(exportFile, file)) {
        LOG.assertTrue(file == null, "Component " + component + " serialize itself into " + file + " and " + exportFile);
        // found
        elementProperties.addComponent(component);
        componentToContainingListElement.put(component, elementProperties);
        file = exportFile;
      }
    }
  }
  return file != null;
}
 
Example 3
Source File: ArmaPluginApplicationConfigurable.java    From arma-intellij-plugin with MIT License 5 votes vote down vote up
@Override
public boolean isModified() {
	String enteredDir = form.getArmaToolsDirectoryPath();
	boolean modified = false;
	File currentArmaToolsDir = ArmaPluginUserData.getInstance().getArmaToolsDirectory();
	if (currentArmaToolsDir == null && enteredDir.length() == 0) {
		modified = false;
	} else {
		//if modified, that means the files aren't equal
		modified = !FileUtil.filesEqual(new File(enteredDir), ArmaPluginUserData.getInstance().getArmaToolsDirectory());
	}
	return modified;
}
 
Example 4
Source File: SourceArtifact.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
  if (obj == this) {
    return true;
  }
  if (!(obj instanceof SourceArtifact)) {
    return false;
  }
  return FileUtil.filesEqual(file, ((SourceArtifact) obj).file);
}
 
Example 5
Source File: ArmaPluginApplicationConfigurable.java    From arma-intellij-plugin with MIT License 5 votes vote down vote up
@Override
public boolean isModified() {
	String enteredDir = form.getArmaToolsDirectoryPath();
	boolean modified = false;
	File currentArmaToolsDir = ArmaPluginUserData.getInstance().getArmaToolsDirectory();
	if (currentArmaToolsDir == null && enteredDir.length() == 0) {
		modified = false;
	} else {
		//if modified, that means the files aren't equal
		modified = !FileUtil.filesEqual(new File(enteredDir), ArmaPluginUserData.getInstance().getArmaToolsDirectory());
	}
	return modified;
}
 
Example 6
Source File: RemoteFileUtil.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
private static boolean isRoot(FilePath file, File[] roots) {
    if (file == null) {
        return true;
    }
    File f = file.getIOFile();
    for (File root : roots) {
        if (FileUtil.filesEqual(root, f)) {
            return true;
        }
    }
    return false;
}
 
Example 7
Source File: PantsSourceRootCompressor.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Checks, whether the child directory is a subdirectory of the base
 * directory.
 *
 * @param base  the base directory.
 * @param child the suspected child directory.
 * @return true, if the child is a subdirectory of the base directory.
 */
public static boolean isYSubDirectoryOfX(File base, File child) {
  File parentFile = child;
  while (parentFile != null) {
    if (FileUtil.filesEqual(base, parentFile)) {
      return true;
    }
    parentFile = parentFile.getParentFile();
  }
  return false;
}
 
Example 8
Source File: ServerConfig.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
private static boolean filesEqual(boolean aSet, @Nullable File aFile, boolean bSet, @Nullable File bFile) {
    return FileUtil.filesEqual(scrubFile(aSet, aFile), scrubFile(bSet, bFile));
}
 
Example 9
Source File: PantsSystemProjectResolver.java    From intellij-pants-plugin with Apache License 2.0 4 votes vote down vote up
@NotNull
private DataNode<ProjectData> resolveProjectInfoImpl(
  @NotNull ExternalSystemTaskId id,
  @NotNull final PantsCompileOptionsExecutor executor,
  @NotNull ExternalSystemTaskNotificationListener listener,
  @NotNull PantsExecutionSettings settings,
  boolean isPreviewMode
) throws ExternalSystemException, IllegalArgumentException, IllegalStateException {
  String projectName = settings.getProjectName().orElseGet(executor::getDefaultProjectName);
  Path projectPath = Paths.get(
    executor.getBuildRoot().getPath(),
    ".idea",
    "pants-projects",
    // Use a timestamp hash to avoid module creation dead lock
    // when overlapping targets were imported into multiple projects
    // from the same Pants repo.
    DigestUtils.sha1Hex(Long.toString(System.currentTimeMillis())),
    executor.getProjectRelativePath()
  );

  final ProjectData projectData = new ProjectData(
    PantsConstants.SYSTEM_ID,
    projectName,
    projectPath.toString(),
    executor.getProjectPath()
  );
  final DataNode<ProjectData> projectDataNode = new DataNode<>(ProjectKeys.PROJECT, projectData, null);

  PantsUtil.findPantsExecutable(executor.getProjectPath())
    .flatMap(file -> PantsSdkUtil.getDefaultJavaSdk(file.getPath(), null))
    .map(sdk -> new ProjectSdkData(sdk.getName()))
    .ifPresent(sdk -> projectDataNode.createChild(ProjectSdkData.KEY, sdk));

  if (!isPreviewMode) {
    PantsExternalMetricsListenerManager.getInstance().logIsIncrementalImport(settings.incrementalImportDepth().isPresent());
    resolveUsingPantsGoal(id, executor, listener, projectDataNode);

    if (!containsContentRoot(projectDataNode, executor.getProjectDir())) {
      // Add a module with content root as import project directory path.
      // This will allow all the files in the imported project directory will be indexed by the plugin.
      final String moduleName = executor.getRootModuleName();
      final ModuleData moduleData = new ModuleData(
        PantsConstants.PANTS_PROJECT_MODULE_ID_PREFIX + moduleName,
        PantsConstants.SYSTEM_ID,
        ModuleTypeId.JAVA_MODULE,
        moduleName + PantsConstants.PANTS_PROJECT_MODULE_SUFFIX,
        projectData.getIdeProjectFileDirectoryPath() + "/" + moduleName,
        executor.getProjectPath()
      );
      final DataNode<ModuleData> moduleDataNode = projectDataNode.createChild(ProjectKeys.MODULE, moduleData);
      final ContentRootData contentRoot = new ContentRootData(PantsConstants.SYSTEM_ID, executor.getProjectDir());
      if (FileUtil.filesEqual(executor.getBuildRoot(), new File(executor.getProjectPath()))) {
        contentRoot.storePath(ExternalSystemSourceType.EXCLUDED, executor.getBuildRoot().getPath() + "/.idea");
      }
      moduleDataNode.createChild(ProjectKeys.CONTENT_ROOT, contentRoot);
    }
  }

  return projectDataNode;
}
 
Example 10
Source File: PantsSourceRootCompressor.java    From intellij-pants-plugin with Apache License 2.0 4 votes vote down vote up
/***
 * Find the top level path ancestors that cover all the path.
 *
 * For example.
 * Input:
 * a/b/c
 * a/b/c/d
 * a/b/c/e
 * a/b/c/f/g
 * Output: a/b/c
 *
 * Input:
 * a/b/c
 * a/b/c/d
 * a/b/e
 * Output:
 * a/b/c
 * a/b/e
 *
 * @param candidates a set of `File`s
 * @return the top ancestors among the candidates
 */
protected static Set<File> findAncestors(Set<File> candidates) {
  Set<File> results = Sets.newHashSet();
  results.addAll(candidates);

  // TODO(yic): the algorithm is n^2, but typically a target would not have more than 5 content roots, and most of the time it only has 1.
  // Like bubble sort, n^2 is not always bad.
  for (File x : candidates) {
    for (File y : candidates) {
      if (FileUtil.filesEqual(x, y)) {
        continue;
      }
      if (isYSubDirectoryOfX(x, y)) {
        results.remove(y);
      }
    }
  }
  return results;
}
 
Example 11
Source File: DeploymentUtilImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void copyFile(@Nonnull final File fromFile,
                     @Nonnull final File toFile,
                     @Nonnull CompileContext context,
                     @Nullable Set<String> writtenPaths,
                     @Nullable FileFilter fileFilter) throws IOException {
  if (fileFilter != null && !fileFilter.accept(fromFile)) {
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Skipping " + fromFile.getAbsolutePath() + ": it wasn't accepted by filter " + fileFilter);
    }
    return;
  }
  checkPathDoNotNavigatesUpFromFile(fromFile);
  checkPathDoNotNavigatesUpFromFile(toFile);
  if (fromFile.isDirectory()) {
    final File[] fromFiles = fromFile.listFiles();
    toFile.mkdirs();
    for (File file : fromFiles) {
      copyFile(file, new File(toFile, file.getName()), context, writtenPaths, fileFilter);
    }
    return;
  }
  if (toFile.isDirectory()) {
    context.addMessage(CompilerMessageCategory.ERROR,
                       CompilerBundle.message("message.text.destination.is.directory", createCopyErrorMessage(fromFile, toFile)), null, -1, -1);
    return;
  }
  if (FileUtil.filesEqual(fromFile, toFile) || writtenPaths != null && !writtenPaths.add(toFile.getPath())) {
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Skipping " + fromFile.getAbsolutePath() + ": " + toFile.getAbsolutePath() + " is already written");
    }
    return;
  }
  if (!FileUtil.isFilePathAcceptable(toFile, fileFilter)) {
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Skipping " + fromFile.getAbsolutePath() + ": " + toFile.getAbsolutePath() + " wasn't accepted by filter " + fileFilter);
    }
    return;
  }
  context.getProgressIndicator().setText("Copying files");
  context.getProgressIndicator().setText2(fromFile.getPath());
  try {
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Copy file '" + fromFile + "' to '"+toFile+"'");
    }
    if (toFile.exists() && !SystemInfo.isFileSystemCaseSensitive) {
      File canonicalFile = toFile.getCanonicalFile();
      if (!canonicalFile.getAbsolutePath().equals(toFile.getAbsolutePath())) {
        FileUtil.delete(toFile);
      }
    }
    FileUtil.copy(fromFile, toFile);
  }
  catch (IOException e) {
    context.addMessage(CompilerMessageCategory.ERROR, createCopyErrorMessage(fromFile, toFile) + ": "+ ExceptionUtil.getThrowableText(e), null, -1, -1);
  }
}
 
Example 12
Source File: StateCache.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isEqual(File val1, File val2) {
  return FileUtil.filesEqual(val1, val2);
}
 
Example 13
Source File: ApplyPatchDifferentiatedDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
private boolean basePathWasChanged(@Nonnull AbstractFilePatchInProgress patchInProgress) {
  return !FileUtil.filesEqual(patchInProgress.myIoCurrentBase, new File(myProject.getBasePath(), patchInProgress.getOriginalBeforePath()));
}