@Override
 public void setUp() throws Exception {
   super.setUp();
   createMockSdk();
   final File currentTestRoot = new File(TEST_DATA_IMPORT, getTestName(true));
   FileUtil.copyDir(currentTestRoot, new File(getProject().getBaseDir().getPath()));
 }
 public static void copyDir(
     @NotNull File fromDir, @NotNull File toDir, @Nullable final FileFilter filter)
     throws IOException {
   ensureExists(toDir);
   if (isAncestor(fromDir, toDir, true)) {
     LOG.error(fromDir.getAbsolutePath() + " is ancestor of " + toDir + ". Can't copy to itself.");
     return;
   }
   File[] files = fromDir.listFiles();
   if (files == null)
     throw new IOException(
         CommonBundle.message("exception.directory.is.invalid", fromDir.getPath()));
   if (!fromDir.canRead())
     throw new IOException(
         CommonBundle.message("exception.directory.is.not.readable", fromDir.getPath()));
   for (File file : files) {
     if (filter != null && !filter.accept(file)) {
       continue;
     }
     if (file.isDirectory()) {
       copyDir(file, new File(toDir, file.getName()), filter);
     } else {
       copy(file, new File(toDir, file.getName()));
     }
   }
 }
 private void copyFileOrDir(File src, File dst) throws IOException {
   if (src.isDirectory()) {
     FileUtil.copyDir(src, dst);
   } else {
     FileUtil.copy(src, dst);
   }
 }
  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);
    delete(classesDir.getParent());

    FileUtil.copyDir(targetDir, new File(myRoot.getPath(), "target"));
    VirtualFileManager.getInstance().syncRefresh(); // shouldn't throw
  }
 /**
  * Copies content of {@code fromDir} to {@code toDir}. It's equivalent to "cp -r fromDir/* toDir"
  * unix command.
  *
  * @param fromDir source directory
  * @param toDir destination directory
  * @throws IOException in case of any IO troubles
  */
 public static void copyDirContent(@NotNull File fromDir, @NotNull File toDir) throws IOException {
   File[] children = ObjectUtils.notNull(fromDir.listFiles(), ArrayUtil.EMPTY_FILE_ARRAY);
   for (File child : children) {
     File target = new File(toDir, child.getName());
     if (child.isFile()) {
       copy(child, target);
     } else {
       copyDir(child, target, true);
     }
   }
 }
    public void cloneToModule(String gitUrl) throws ServerRuntimeException {
      File cloneDir = cloneToTemp(gitUrl);

      try {
        FileUtil.copyDir(cloneDir, getContentRootFile());
      } catch (IOException e) {
        throw new ServerRuntimeException(e);
      }

      refreshApplicationRepository();
    }
  @Before
  public void setUp() throws Exception {
    Runner.initLogger();
    myTempDirFixture = IdeaTestFixtureFactory.getFixtureFactory().createTempDirTestFixture();
    myTempDirFixture.setUp();

    FileUtil.copyDir(PathManagerEx.findFileUnderCommunityHome("updater/testData"), getDataDir());

    boolean windowsLineEnds = new File(getDataDir(), "Readme.txt").length() == 7132;
    CHECKSUMS = new CheckSums(windowsLineEnds);
  }
 public static void copyDir(@NotNull File fromDir, @NotNull File toDir, boolean copySystemFiles)
     throws IOException {
   copyDir(
       fromDir,
       toDir,
       copySystemFiles
           ? null
           : new FileFilter() {
             @Override
             public boolean accept(File file) {
               return !StringUtil.startsWithChar(file.getName(), '.');
             }
           });
 }
Пример #9
0
 private void setUpDataClasses() throws IOException {
   File classesDir =
       new File(
           Test01.class
               .getResource("/" + Test01.class.getPackage().getName().replace('.', '/'))
               .getFile());
   File destDir =
       new File(myModule.getProject().getBaseDir().getPath() + myClassesProjectRelativePath);
   FileUtil.copyDir(classesDir, destDir);
   VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(destDir);
   assertNotNull(vFile);
   PsiTestUtil.addLibrary(
       myModule, "dataClasses", vFile.getPath(), new String[] {""}, ArrayUtil.EMPTY_STRING_ARRAY);
 }
 protected String copyToProject(String relativeSourcePath, String relativeTargetPath) {
   File source = findFindUnderProjectHome(relativeSourcePath);
   String fullTargetPath = getAbsolutePath(relativeTargetPath);
   File target = new File(fullTargetPath);
   try {
     if (source.isDirectory()) {
       FileUtil.copyDir(source, target);
     } else {
       FileUtil.copy(source, target);
     }
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
   return fullTargetPath;
 }
  protected void setUp() throws Exception {
    super.setUp();
    myTempDir = FileUtil.createTempDirectory("GitRepositoryReaderTest", null);

    File pluginRoot = new File(PluginPathManager.getPluginHomePath("git4idea"));
    File dataDir = new File(new File(pluginRoot, "testData"), "repo");

    FileUtil.copyDir(dataDir, myTempDir);
    myGitDir = new File(myTempDir, ".git");
    FileUtil.rename(new File(myTempDir, "dot_git"), myGitDir);
    assertTrue(myGitDir.exists());
    myRepositoryReader = new GitRepositoryReader(myGitDir);

    myLocalBranches = readBranches(true);
    myRemoteBranches = readBranches(false);
  }
 protected void copyToProject(String relativePath) {
   File dir = PathManagerEx.findFileUnderProjectHome(relativePath, getClass());
   final File target = new File(FileUtil.toSystemDependentName(getProjectBasePath()));
   try {
     FileUtil.copyDir(dir, target);
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
   new WriteAction() {
     protected void run(final Result result) {
       VirtualFile virtualDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(target);
       assertNotNull(target.getAbsolutePath() + " not found", virtualDir);
       virtualDir.refresh(false, true);
     }
   }.execute();
 }
Пример #13
0
  private void updateData(MavenProgressIndicator progress) throws MavenIndexException {
    String newDataDirName;
    IndexData newData;

    newDataDirName = findAvailableDataDirName();
    try {
      FileUtil.copyDir(getUpdateDir(), getDataContextDir(getDataDir(newDataDirName)));
    } catch (IOException e) {
      throw new MavenIndexException(e);
    }
    newData = openData(newDataDirName);

    try {
      doUpdateIndexData(newData, progress);
      newData.flush();
    } catch (Throwable e) {
      newData.close(true);
      FileUtil.delete(getDataDir(newDataDirName));

      if (e instanceof MavenServerIndexerException) throw new MavenIndexException(e);
      if (e instanceof IOException) throw new MavenIndexException(e);
      throw new RuntimeException(e);
    }

    synchronized (this) {
      IndexData oldData = myData;

      myData = newData;
      myDataDirName = newDataDirName;

      myUpdateTimestamp = System.currentTimeMillis();

      oldData.close(true);

      File[] children = myDir.listFiles();
      if (children != null) {
        for (File each : children) {
          if (each.getName().startsWith(DATA_DIR_PREFIX)
              && !each.getName().equals(newDataDirName)) {
            FileUtil.delete(each);
          }
        }
      }
    }
  }
  private static void copyLanguageJSAccessoriesFromDir(
      String languageBundleHome, File targetSources) {
    File languageHome = new File(languageBundleHome);
    if (!languageHome.exists() || !languageHome.isDirectory()) {
      LOG.error("Illegal language dir: " + languageBundleHome);
      return;
    }

    File jsSourceDir = new File(languageHome, JS_GEN_DIR);
    if (jsSourceDir.exists() && jsSourceDir.isDirectory()) {
      try {
        FileUtil.copyDir(jsSourceDir, targetSources);
      } catch (IOException e) {
        LOG.error("Can't copy JS generated sources from " + jsSourceDir + " to " + targetSources);
        return;
      }
    }
  }
  public void updateOrRepair(
      boolean fullUpdate, MavenGeneralSettings settings, MavenProgressIndicator progress)
      throws MavenProcessCanceledException {
    try {
      final File newDataDir = createNewDataDir();
      final File newDataContextDir = getDataContextDir(newDataDir);
      final File currentDataContextDir = getCurrentDataContextDir();

      boolean reuseExistingContext =
          fullUpdate
              ? myKind != Kind.LOCAL && hasValidContext(currentDataContextDir)
              : hasValidContext(currentDataContextDir);

      fullUpdate = fullUpdate || !reuseExistingContext && myKind == Kind.LOCAL;

      if (reuseExistingContext) {
        try {
          FileUtil.copyDir(currentDataContextDir, newDataContextDir);
        } catch (IOException e) {
          throw new MavenIndexException(e);
        }
      }

      if (fullUpdate) {
        int context = createContext(newDataContextDir, "update");
        try {
          updateContext(context, settings, progress);
        } finally {
          myIndexer.releaseIndex(context);
        }
      }

      updateData(progress, newDataDir, fullUpdate);

      isBroken = false;
      myFailureMessage = null;
    } catch (MavenProcessCanceledException e) {
      throw e;
    } catch (Exception e) {
      handleUpdateException(e);
    }

    save();
  }
Пример #16
0
  protected void setUp() throws Exception {
    super.setUp();
    myTempDirectory = FileUtil.createTempDirectory(getTestName(true), "test");
    myFilesToDelete.add(getTestContentFile());
    final File testRoot = new File(getTestDataPath(), getTestPath());
    assertTrue(testRoot.getAbsolutePath(), testRoot.isDirectory());

    final File currentTestRoot = new File(testRoot, getTestDirectoryName());
    assertTrue(currentTestRoot.getAbsolutePath(), currentTestRoot.isDirectory());

    FileUtil.copyDir(currentTestRoot, new File(myTempDirectory, getTestDirectoryName()));

    ApplicationManager.getApplication()
        .runWriteAction(
            new Runnable() {
              public void run() {
                setupContentRoot();
              }
            });
  }
 public static void copyDir(@NotNull File fromDir, @NotNull File toDir) throws IOException {
   copyDir(fromDir, toDir, true);
 }
  private static void copy(
      @NotNull File src,
      @NotNull File dest,
      ConfigImportSettings settings,
      File oldInstallationHome)
      throws IOException {
    src = src.getCanonicalFile();
    dest = dest.getCanonicalFile();
    if (!src.isDirectory()) {
      throw new IOException(
          ApplicationBundle.message(
              "config.import.invalid.directory.error", src.getAbsolutePath()));
    }
    if (!dest.isDirectory()) {
      throw new IOException(
          ApplicationBundle.message(
              "config.import.invalid.directory.error", dest.getAbsolutePath()));
    }
    if (FileUtil.filesEqual(src, dest)) {
      return;
    }

    FileUtil.ensureExists(dest);

    File[] childFiles =
        src.listFiles(
            new FilenameFilter() {
              @Override
              public boolean accept(@NotNull File dir, @NotNull String name) {
                // Don't copy plugins just imported. They're most probably incompatible with newer
                // idea version.
                return !StringUtil.startsWithChar(name, '.') && !name.equals(PLUGINS_PATH);
              }
            });

    if (childFiles == null || childFiles.length == 0) {
      return;
    }

    for (File from : childFiles) {
      File to = new File(dest, from.getName());
      if (from.isDirectory()) {
        FileUtil.copyDir(from, to, false);
      } else {
        FileUtil.copy(from, to);
      }
    }

    File plugins = new File(src, PLUGINS_PATH);
    if (!loadOldPlugins(plugins, dest) && SystemInfo.isMac) {
      File oldPluginsDir =
          getOldPath(
              oldInstallationHome,
              settings,
              PathManager.PROPERTY_PLUGINS_PATH,
              new Function<String, String>() {
                @Override
                public String fun(String pathSelector) {
                  return PathManager.getDefaultPluginPathFor(pathSelector);
                }
              });
      if (oldPluginsDir == null) {
        // e.g. installation home referred to config home. Try with default selector, same as config
        // name
        oldPluginsDir = new File(PathManager.getDefaultPluginPathFor(src.getName()));
      }
      loadOldPlugins(oldPluginsDir, dest);
    }
  }
 public void setUp() throws Exception {
   super.setUp();
   final File currentTestRoot = new File("testData/rebar/sampleProject");
   FileUtil.copyDir(currentTestRoot, new File(getProject().getBaseDir().getPath()));
 }