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

The following examples show how to use com.intellij.openapi.util.io.FileUtil#copyDir() . 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: ProjectWrangler.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public File copyProjectBeforeOpening(@NotNull String projectDirName) throws IOException {
  File masterProjectPath = getMasterProjectDirPath(projectDirName);

  File projectPath = getTestProjectDirPath(projectDirName);
  if (projectPath.isDirectory()) {
    FileUtilRt.delete(projectPath);
  }
  // If masterProjectPath contains a src.zip file, unzip the file to projectPath.
  // Otherwise, copy the whole directory to projectPath.
  File srcZip = new File(masterProjectPath, SRC_ZIP_NAME);
  if (srcZip.exists() && srcZip.isFile()) {
    ZipUtil.unzip(null, projectPath, srcZip, null, null, true);
  }
  else {
    FileUtil.copyDir(masterProjectPath, projectPath);
  }
  return projectPath;
}
 
Example 2
Source File: CopyingCompiler.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public ProcessingItem[] process(CompileContext context, ProcessingItem[] items) {
  final List<ProcessingItem> successfullyProcessed = new ArrayList<ProcessingItem>(items.length);
  for (ProcessingItem item : items) {
    final CopyItem copyItem = (CopyItem)item;
    final String toPath = copyItem.getDestinationPath();
    try {
      if (isDirectoryCopying()) {
        FileUtil.copyDir(copyItem.getFile(), new File(toPath));
      }
      else {
        FileUtil.copy(copyItem.getFile(), new File(toPath));
      }

      successfullyProcessed.add(copyItem);
    }
    catch (IOException e) {
      context.addMessage(CompilerMessageCategory.ERROR, CompilerBundle.message("error.copying", item.getFile().getPath(), toPath, e.getMessage()), null, -1,
                         -1);
    }
  }
  return successfullyProcessed.toArray(new ProcessingItem[successfullyProcessed.size()]);
}
 
Example 3
Source File: ModuleTestCase.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected Module createModuleFromTestData(final String dirInTestData, final String newModuleFileName, final boolean addSourceRoot) throws IOException {
  final File dirInTestDataFile = new File(dirInTestData);
  assertTrue(dirInTestDataFile.isDirectory());
  final File moduleDir = createTempDirectory();
  FileUtil.copyDir(dirInTestDataFile, moduleDir);
  final Module module = createModule(moduleDir + "/" + newModuleFileName);
  final VirtualFile root = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(moduleDir);
  assertNotNull(root);
  new WriteCommandAction.Simple(module.getProject()) {
    @Override
    protected void run() throws Throwable {
      root.refresh(false, true);
    }
  }.execute().throwException();
  if (addSourceRoot) {
    PsiTestUtil.addSourceContentToRoots(module, root);
  }
  else {
    PsiTestUtil.addContentRoot(module, root);
  }
  return module;
}
 
Example 4
Source File: ExternalChangesAndRefreshingTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void testCreationOfExcludedDirWithFilesDuringRefreshShouldNotThrowException() throws Exception {
  // there was a problem with the DirectoryIndex - the files that were created during the refresh
  // were not correctly excluded, thereby causing the LocalHistory to fail during addition of 
  // files under the excluded dir.

  File targetDir = createTargetDir();
  FileUtil.copyDir(targetDir, new File(myRoot.getPath(), "target"));
  VirtualFileManager.getInstance().syncRefresh();

  String classesPath = myRoot.getPath() + "/target/classes";
  addExcludedDir(classesPath);
  final VirtualFile classesDir = LocalFileSystem.getInstance().findFileByPath(classesPath);
  assertNotNull(classesDir);
  classesDir.getParent().delete(this);

  FileUtil.copyDir(targetDir, new File(myRoot.getPath(), "target"));
  VirtualFileManager.getInstance().syncRefresh(); // shouldn't throw
}
 
Example 5
Source File: PantsUtil.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
public static void copyDirContent(@NotNull File fromDir, @NotNull File toDir) throws IOException {
  final File[] children = ObjectUtils.notNull(fromDir.listFiles(), ArrayUtil.EMPTY_FILE_ARRAY);
  for (File child : children) {
    final File target = new File(toDir, child.getName());
    if (child.isFile()) {
      FileUtil.copy(child, target);
    }
    else {
      FileUtil.copyDir(child, target, false);
    }
  }
}