@Nullable
 public VirtualFile getBeforeVFUnderProject(final Project project) {
   if (myBeforePath == null || project.getBaseDir() == null) return null;
   final File baseDir = new File(project.getBaseDir().getPath());
   final File file = new File(baseDir, myBeforePath);
   return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
 }
 static void createProjectStructure(@NotNull Project project, @NotNull Collection<String> paths) {
   for (String path : paths) {
     cd(project.getBaseDir().getPath());
     File f = new File(project.getBaseDir().getPath(), path);
     f.mkdirs();
     LocalFileSystem.getInstance().refreshAndFindFileByIoFile(f);
   }
 }
 public void validate() {
   this.myValid = false;
   if (!new File(myProject.getBaseDir().getPath()).exists()) {
     LOG.error("Work dir not found " + myProject.getBaseDir().getPath());
     return;
   }
   try {
     myCommandLine = buildCommandLine(collectClassPath());
   } catch (Exception e) {
     LOG.error(e);
     return;
   }
   this.myValid = true;
 }
 @Override
 public void actionPerformed(AnActionEvent e) {
   final Project project = getEventProject(e);
   final VirtualFile[] files = e.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY);
   FeatureUsageTracker.getInstance().triggerFeatureUsed("jar.diff");
   if (project != null && files != null) {
     VirtualFileDiffElement src = null;
     VirtualFileDiffElement trg = null;
     if (files.length == 2 && isArchive(files[0]) && isArchive(files[1])) {
       src = new JarFileDiffElement(files[0]);
       trg = new JarFileDiffElement(files[1]);
     } else if (files.length == 1 && isArchive(files[0])) {
       src = new JarFileDiffElement(files[0]);
       final FileChooserDescriptor descriptor =
           new FileChooserDescriptor(true, false, true, true, false, false) {
             @Override
             public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
               return file.isDirectory() || (!file.isDirectory() && isArchive(file));
             }
           };
       final VirtualFile[] result =
           FileChooser.chooseFiles(descriptor, project, project.getBaseDir());
       if (result.length == 1 && result[0] != null && isArchive(result[0])) {
         trg = new JarFileDiffElement(result[0]);
       }
     }
     final DirDiffManager mgr = DirDiffManager.getInstance(project);
     if (src != null && trg != null && mgr.canShow(src, trg)) {
       mgr.showDiff(src, trg, new DirDiffSettings(), null);
     }
   }
 }
  public Change getChange(Project project) {
    // todo unify with
    if (myChange == null) {
      File baseDir = new File(project.getBaseDir().getPath());

      File file = getAbsolutePath(baseDir, myBeforePath);
      FilePath beforePath = VcsUtil.getFilePath(file, false);
      beforePath.refresh();
      ContentRevision beforeRevision = null;
      if (myFileStatus != FileStatus.ADDED) {
        beforeRevision =
            new CurrentContentRevision(beforePath) {
              @Override
              @NotNull
              public VcsRevisionNumber getRevisionNumber() {
                return new TextRevisionNumber(VcsBundle.message("local.version.title"));
              }
            };
      }
      ContentRevision afterRevision = null;
      if (myFileStatus != FileStatus.DELETED) {
        FilePath afterPath = VcsUtil.getFilePath(getAbsolutePath(baseDir, myAfterPath), false);
        afterRevision = new PatchedContentRevision(project, beforePath, afterPath);
      }
      myChange = new Change(beforeRevision, afterRevision, myFileStatus);
    }
    return myChange;
  }
  @Nullable
  static String getRelativePath(final VirtualFile virtualFile, final Project project) {
    String url = virtualFile.getPresentableUrl();
    if (project == null) {
      return url;
    }
    VirtualFile root =
        ProjectFileIndex.SERVICE.getInstance(project).getContentRootForFile(virtualFile);
    if (root != null) {
      return root.getName()
          + File.separatorChar
          + VfsUtilCore.getRelativePath(virtualFile, root, File.separatorChar);
    }

    final VirtualFile baseDir = project.getBaseDir();
    if (baseDir != null) {
      //noinspection ConstantConditions
      final String projectHomeUrl = baseDir.getPresentableUrl();
      if (url.startsWith(projectHomeUrl)) {
        final String cont = url.substring(projectHomeUrl.length());
        if (cont.isEmpty()) return null;
        url = "..." + cont;
      }
    }
    return url;
  }
 @NotNull
 public static Module doCreateRealModuleIn(
     @NotNull String moduleName,
     @NotNull final Project project,
     @NotNull final ModuleType moduleType) {
   final VirtualFile baseDir = project.getBaseDir();
   assertNotNull(baseDir);
   final File moduleFile =
       new File(
           baseDir.getPath().replace('/', File.separatorChar),
           moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION);
   FileUtil.createIfDoesntExist(moduleFile);
   myFilesToDelete.add(moduleFile);
   return new WriteAction<Module>() {
     @Override
     protected void run(@NotNull Result<Module> result) throws Throwable {
       final VirtualFile virtualFile =
           LocalFileSystem.getInstance().refreshAndFindFileByIoFile(moduleFile);
       assert virtualFile != null;
       Module module =
           ModuleManager.getInstance(project).newModule(virtualFile.getPath(), moduleType.getId());
       module.getModuleFile();
       result.setResult(module);
     }
   }.execute().getResultObject();
 }
  public void launch(final MPSMakeCallback callback) {
    if (!isValid()) {
      throw new IllegalStateException("Unable to launch without validation");
    }

    GeneralCommandLine gcl = new GeneralCommandLine(myCommandLine);
    gcl.setWorkDirectory(myProject.getBaseDir().getPath());
    final TextEventProcessor tep =
        new TextEventProcessor(myProject, "MPS") {
          @Override
          public void reportWrittenFile(String file) {
            LOG.debug("written file: " + file);
            callback.fileWritten(file);
          }

          @Override
          public void reportDeletedFile(String file) {
            LOG.debug("deleted file: " + file);
            callback.fileDeleted(file);
          }

          @Override
          public void error(String text) {
            LOG.debug("error: " + text);
            callback.error(text);
          }

          @Override
          public void info(String text) {
            LOG.info("info: " + text);
            callback.info(text);
          }
        };
    try {
      OSProcessHandler processHandler =
          new OSProcessHandler(gcl.createProcess(), myCommandLine.get(0));
      processHandler.addProcessListener(
          new ProcessAdapter() {
            @Override
            public void onTextAvailable(ProcessEvent event, Key outputType) {
              if (outputType == ProcessOutputTypes.STDERR) {
                tep.processStderr(event.getText());
              } else if (outputType == ProcessOutputTypes.STDOUT) {
                tep.processStdout(event.getText());
              }
            }
          });
      processHandler.startNotify();

      processHandler.waitFor();
      if (processHandler.getProcess().exitValue() != 0) {
        callback.error("External process returned non-zero");
      }

    } catch (ExecutionException e) {
      LOG.debug(e);
      callback.error("Error running process: " + e.getMessage());
    }
  }
  private void make(
      final CompileContext context,
      final Chunk<Module> moduleChunk,
      VirtualFile[] files,
      OutputSink sink) {
    String basePath = project.getBaseDir().getPath();
    File makeFile = new File(basePath, "/Makefile");
    if (!makeFile.exists()) {
      // TODO Generate the Makefile
      context.addMessage(
          CompilerMessageCategory.ERROR,
          "Makefile doesn't exist at " + makeFile.getPath(),
          null,
          -1,
          -1);
    } else {
      GeneralCommandLine command = new GeneralCommandLine();
      final Sdk projectSdk = null;
      final GoSdkData goSdkData = goSdkData(projectSdk);
      command.setExePath(getMakeBinary(projectSdk));
      command.addParameter("-C");
      command.addParameter(project.getBaseDir().getPath());
      command.addParameter("-f");
      command.addParameter(makeFile.getPath());
      command.addParameter("-e");
      command.addParameter("install");
      command.addParameter("clean");
      command
          .getEnvironment()
          .putAll(
              new HashMap<String, String>() {
                {
                  put("GOROOT", projectSdk.getHomePath());
                  put("GOARCH", goSdkData.TARGET_ARCH.getName());
                  put("GOOS", goSdkData.TARGET_OS.getName());
                  put("GOBIN", goSdkData.GO_BIN_PATH);
                  put("PATH", System.getenv("PATH") + File.pathSeparator + goSdkData.GO_BIN_PATH);
                  put("TARGDIR", getOutputPath(context, moduleChunk));
                }
              });

      CompilationTaskWorker compilationTaskWorker =
          new CompilationTaskWorker(new MakeOutputStreamParser(projectSdk, goSdkData, basePath));
      compilationTaskWorker.executeTask(command, basePath, context);
    }
  }
 public AutoMatchIterator(final Project project) {
   myProject = project;
   final VirtualFile baseDir = myProject.getBaseDir();
   myStrategies = new LinkedList<AutoMatchStrategy>();
   myStrategies.add(new OneBaseStrategy(baseDir));
   myStrategies.add(new IndividualPiecesStrategy(baseDir));
   myStrategies.add(new DefaultPatchStrategy(baseDir));
 }
  @Before
  public void setUp() {
    unit = new FileConfigurationLocation(project);
    unit.setLocation("aLocation");
    unit.setDescription("aDescription");

    when(project.getBaseDir()).thenReturn(projectBase);
    when(projectBase.getPath()).thenReturn(PROJECT_PATH);
  }
  public ShelvedChangeList shelveChanges(
      final Collection<Change> changes, final String commitMessage, final boolean rollback)
      throws IOException, VcsException {
    final List<Change> textChanges = new ArrayList<Change>();
    final List<ShelvedBinaryFile> binaryFiles = new ArrayList<ShelvedBinaryFile>();
    for (Change change : changes) {
      if (ChangesUtil.getFilePath(change).isDirectory()) {
        continue;
      }
      if (change.getBeforeRevision() instanceof BinaryContentRevision
          || change.getAfterRevision() instanceof BinaryContentRevision) {
        binaryFiles.add(shelveBinaryFile(change));
      } else {
        textChanges.add(change);
      }
    }

    final ShelvedChangeList changeList;
    try {
      File patchPath = getPatchPath(commitMessage);
      ProgressManager.checkCanceled();
      final List<FilePatch> patches =
          IdeaTextPatchBuilder.buildPatch(
              myProject, textChanges, myProject.getBaseDir().getPresentableUrl(), false);
      ProgressManager.checkCanceled();

      CommitContext commitContext = new CommitContext();
      baseRevisionsOfDvcsIntoContext(textChanges, commitContext);
      myFileProcessor.savePathFile(
          new CompoundShelfFileProcessor.ContentProvider() {
            public void writeContentTo(final Writer writer, CommitContext commitContext)
                throws IOException {
              UnifiedDiffWriter.write(myProject, patches, writer, "\n", commitContext);
            }
          },
          patchPath,
          commitContext);

      changeList =
          new ShelvedChangeList(
              patchPath.toString(), commitMessage.replace('\n', ' '), binaryFiles);
      myShelvedChangeLists.add(changeList);
      ProgressManager.checkCanceled();

      if (rollback) {
        new RollbackWorker(myProject, false)
            .doRollback(changes, true, null, VcsBundle.message("shelve.changes.action"));
      }
    } finally {
      notifyStateChanged();
    }

    return changeList;
  }
 @NotNull
 public static String getCreationPlace(@NotNull Project project) {
   String place = project.getUserData(CREATION_PLACE);
   Object base;
   try {
     base = project.isDisposed() ? "" : project.getBaseDir();
   } catch (Exception e) {
     base = " (" + e + " while getting base dir)";
   }
   return project + (place != null ? place : "") + base;
 }
  public Map<VirtualFile, RepositoryLocation> getRoots() {
    myContentRoots = myPlManager.getRootsUnderVcs(myVcs);

    List<VirtualFile> roots = new ArrayList<>();
    final List<VcsDirectoryMapping> mappings = myPlManager.getDirectoryMappings(myVcs);
    for (VcsDirectoryMapping mapping : mappings) {
      if (mapping.isDefaultMapping()) {
        if (myVcs.equals(myPlManager.getVcsFor(myProject.getBaseDir()))) {
          roots.add(myProject.getBaseDir());
        }
      } else {
        VirtualFile newFile = LocalFileSystem.getInstance().findFileByPath(mapping.getDirectory());
        if (newFile == null) {
          newFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(mapping.getDirectory());
        }
        if (newFile != null) {
          roots.add(newFile);
        } else {
          LOG.info("Can not file virtual file for root: " + mapping.getDirectory());
        }
      }
    }
    ContainerUtil.addAll(roots, myContentRoots);
    final Map<VirtualFile, RepositoryLocation> result = new HashMap<>();
    for (Iterator<VirtualFile> iterator = roots.iterator(); iterator.hasNext(); ) {
      final VirtualFile vf = iterator.next();
      final RepositoryLocation location =
          myLocationCache.getLocation(myVcs, VcsUtil.getFilePath(vf), false);
      if (location != null) {
        result.put(vf, location);
      } else {
        iterator.remove();
      }
    }
    roots = myVcs.filterUniqueRoots(roots, IntoSelfVirtualFileConvertor.getInstance());
    result.keySet().retainAll(roots);

    logRoots(roots);
    return result;
  }
 @Nullable
 public static String getDefaultArtifactOutputPath(
     @NotNull String artifactName, final @NotNull Project project) {
   final CompilerProjectExtension extension = CompilerProjectExtension.getInstance(project);
   if (extension == null) return null;
   String outputUrl = extension.getCompilerOutputUrl();
   if (outputUrl == null || outputUrl.length() == 0) {
     final VirtualFile baseDir = project.getBaseDir();
     if (baseDir == null) return null;
     outputUrl = baseDir.getUrl() + "/out";
   }
   return VfsUtil.urlToPath(outputUrl) + "/artifacts/" + FileUtil.sanitizeFileName(artifactName);
 }
 private String getDefaultBaseDir(WizardContext wizardContext) {
   if (wizardContext.isCreatingNewProject()) {
     return myNamePathComponent.getPath();
   } else {
     final Project project = wizardContext.getProject();
     assert project != null;
     final VirtualFile baseDir = project.getBaseDir();
     if (baseDir != null) {
       return baseDir.getPath();
     }
     return "";
   }
 }
  @Nullable
  private static VirtualFile guessRootForVcs(
      @NotNull Project project, @Nullable AbstractVcs vcs, @Nullable String defaultRootPathValue) {
    if (project.isDisposed()) return null;
    LOG.debug("Guessing vcs root...");
    ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);
    if (vcs == null) {
      LOG.debug("Vcs not found.");
      return null;
    }
    String vcsName = vcs.getDisplayName();
    VirtualFile[] vcsRoots = vcsManager.getRootsUnderVcs(vcs);
    if (vcsRoots.length == 0) {
      LOG.debug("No " + vcsName + " roots in the project.");
      return null;
    }

    if (vcsRoots.length == 1) {
      VirtualFile onlyRoot = vcsRoots[0];
      LOG.debug("Only one " + vcsName + " root in the project, returning: " + onlyRoot);
      return onlyRoot;
    }

    // get remembered last visited repository root
    if (defaultRootPathValue != null) {
      VirtualFile recentRoot = VcsUtil.getVirtualFile(defaultRootPathValue);
      if (recentRoot != null) {
        LOG.debug("Returning the recent root: " + recentRoot);
        return recentRoot;
      }
    }

    // otherwise return the root of the project dir or the root containing the project dir, if there
    // is such
    VirtualFile projectBaseDir = project.getBaseDir();
    if (projectBaseDir == null) {
      VirtualFile firstRoot = vcsRoots[0];
      LOG.debug("Project base dir is null, returning the first root: " + firstRoot);
      return firstRoot;
    }
    VirtualFile rootCandidate;
    for (VirtualFile root : vcsRoots) {
      if (root.equals(projectBaseDir) || VfsUtilCore.isAncestor(root, projectBaseDir, true)) {
        LOG.debug("The best candidate: " + root);
        return root;
      }
    }
    rootCandidate = vcsRoots[0];
    LOG.debug("Returning the best candidate: " + rootCandidate);
    return rootCandidate;
  }
  @Nullable
  @Override
  public VirtualFile getCompilerOutput() {
    if (myOutputDirPointer == null) {
      VirtualFile baseDir = myProject.getBaseDir();
      if (baseDir == null) {
        return null;
      }
      VirtualFile outDir = baseDir.findFileByRelativePath(DEFAULT_OUTPUT_URL);

      return outDir == null ? null : outDir;
    }
    return myOutputDirPointer.getFile();
  }
Beispiel #19
0
  public static VirtualFile findTestBaseDir(VirtualFile currentDir, Project project) {
    Boolean continueSearch = true;
    Integer maxDirs = 35;
    Integer dirCount = 0;
    while (continueSearch) {
      dirCount++;
      if (currentDir.equals(project.getBaseDir())) {
        continueSearch = false;
      } else if (dirCount >= maxDirs) {
        continueSearch = false;
      } else {
        if (new File(currentDir.getPath() + "/composer.json").exists()) {
          return currentDir;
        }
      }
      currentDir = currentDir.getParent();
      if (null == currentDir) {
        return project.getBaseDir();
      }
    }

    return project.getBaseDir();
  }
  @NotNull
  public static String getShortRepositoryName(@NotNull Project project, @NotNull VirtualFile root) {
    VirtualFile projectDir = project.getBaseDir();

    String repositoryPath = root.getPresentableUrl();
    if (projectDir != null) {
      String relativePath = VfsUtilCore.getRelativePath(root, projectDir, File.separatorChar);
      if (relativePath != null) {
        repositoryPath = relativePath;
      }
    }

    return repositoryPath.isEmpty() ? root.getName() : repositoryPath;
  }
  @Nullable
  @Override
  public String getCompilerOutputUrl() {
    if (myOutputDirPointer == null) {
      VirtualFile baseDir = myProject.getBaseDir();
      assert baseDir != null;
      VirtualFile outDir = baseDir.findFileByRelativePath(DEFAULT_OUTPUT_URL);

      return outDir == null
          ? myProject.getPresentableUrl() + "/" + DEFAULT_OUTPUT_URL
          : outDir.getUrl();
    }
    return myOutputDirPointer.getUrl();
  }
 private boolean isInDirectoryBasedRoot(final VirtualFile file) {
   if (file == null) return false;
   final StorageScheme storageScheme = ((ProjectEx) myProject).getStateStore().getStorageScheme();
   if (StorageScheme.DIRECTORY_BASED.equals(storageScheme)) {
     final VirtualFile baseDir = myProject.getBaseDir();
     if (baseDir == null) return false;
     final VirtualFile ideaDir = baseDir.findChild(Project.DIRECTORY_STORE_FOLDER);
     return ideaDir != null
         && ideaDir.isValid()
         && ideaDir.isDirectory()
         && VfsUtilCore.isAncestor(ideaDir, file, false);
   }
   return false;
 }
  @Before
  public void setUp() throws Throwable {
    IdeaTestApplication.getInstance();

    myTestName = createTestName();
    myProjectFixture =
        IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(myTestName).getFixture();

    edt(
        new ThrowableRunnable<Exception>() {
          @Override
          public void run() throws Exception {
            myProjectFixture.setUp();
          }
        });

    myProject = myProjectFixture.getProject();

    myProjectRoot = myProject.getBasePath();
    myProjectDir = myProject.getBaseDir();
    myTestRoot = myProjectRoot;

    myGit = ServiceManager.getService(myProject, Git.class);
    mySettings = GitVcsSettings.getInstance(myProject);
    mySettings.getAppSettings().setPathToGit(GitExecutor.PathHolder.GIT_EXECUTABLE);

    // dynamic overriding is used instead of making it in plugin.xml,
    // because MockVcsHelper is not ready to be a full featured implementation for all tests.
    myVcsHelper =
        GitTestUtil.overrideService(myProject, AbstractVcsHelper.class, MockVcsHelper.class);
    myChangeListManager = ChangeListManagerImpl.getInstanceImpl(myProject);
    myNotificator = (TestVcsNotifier) ServiceManager.getService(myProject, VcsNotifier.class);
    myVcs = GitVcs.getInstance(myProject);
    myRepositoryManager = GitUtil.getRepositoryManager(myProject);

    virtualCommits = new GitTestVirtualCommitsHolder();
    myAsyncTasks = new ArrayList<>();

    cd(myProjectRoot);
    myRepository = GitTestUtil.createRepository(myProject, myProjectRoot);

    ProjectLevelVcsManagerImpl vcsManager =
        (ProjectLevelVcsManagerImpl) ProjectLevelVcsManager.getInstance(myProject);
    AbstractVcs vcs = vcsManager.findVcsByName("Git");
    Assert.assertEquals(1, vcsManager.getRootsUnderVcs(vcs).length);

    GitTestUtil.assumeSupportedGitVersion(myVcs);
    LOG.info(getStartTestMarker());
  }
Beispiel #24
0
 @Override
 public void configureModule(
     final Module module, final ModifiableRootModel model, final ContentEntry entry) {
   try {
     LibraryUtil.addXtendLibrary(model);
     Project _project = this.getProject();
     VirtualFile _baseDir = _project.getBaseDir();
     final VirtualFile srcGenFolder = _baseDir.createChildDirectory(null, "xtend-gen");
     entry.addSourceFolder(srcGenFolder, false);
     String _iD = XtendLanguage.INSTANCE.getID();
     LightToolingTest.addFacetToModule(module, _iD);
   } catch (Throwable _e) {
     throw Exceptions.sneakyThrow(_e);
   }
 }
 @Nullable
 public static VirtualFile getRequester(
     @NotNull Project project, @Nullable String configFilePath) {
   VirtualFile requester = null;
   if (configFilePath != null) {
     File configFile = new File(configFilePath);
     if (configFile.isFile()) {
       requester = VfsUtil.findFileByIoFile(configFile, false);
     }
   }
   if (requester == null || !requester.isValid()) {
     requester = project.getBaseDir();
   }
   return requester;
 }
  @Nullable
  private static PsiDirectory tryNotNullizeDirectory(
      @NotNull Project project, @Nullable PsiDirectory defaultTargetDirectory) {
    if (defaultTargetDirectory == null) {
      VirtualFile root =
          ArrayUtil.getFirstElement(ProjectRootManager.getInstance(project).getContentRoots());
      if (root == null) root = project.getBaseDir();
      if (root == null) root = VfsUtil.getUserHomeDir();
      defaultTargetDirectory =
          root != null ? PsiManager.getInstance(project).findDirectory(root) : null;

      if (defaultTargetDirectory == null) {
        LOG.warn("No directory found for project: " + project.getName() + ", root: " + root);
      }
    }
    return defaultTargetDirectory;
  }
 private VirtualFile[] doAdd() {
   VirtualFile baseDir = myAddBaseDir;
   Project project =
       PlatformDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(myPanel));
   if (baseDir == null && project != null) {
     baseDir = project.getBaseDir();
   }
   VirtualFile[] files = FileChooser.chooseFiles(myDescriptor, myPanel, project, baseDir);
   files = adjustAddedFileSet(myPanel, files);
   List<VirtualFile> added = new ArrayList<VirtualFile>(files.length);
   for (VirtualFile vFile : files) {
     if (addElement(vFile)) {
       added.add(vFile);
     }
   }
   return VfsUtil.toVirtualFileArray(added);
 }
 private static String replacePlaceHolders(String template, Project project) {
   String processedTemplate = template;
   String projectName = "";
   String projectBaseDir = "";
   String projectBaseDirName = "";
   if (null != project) {
     projectName = project.getName();
     projectBaseDir = project.getBasePath();
     projectBaseDirName = project.getBaseDir().getName();
   }
   processedTemplate = processedTemplate.replace(PROJECT_NAME.getVariableName(), projectName);
   processedTemplate =
       processedTemplate.replace(PROJECT_BASE_DIR_NAME.getVariableName(), projectBaseDirName);
   processedTemplate =
       processedTemplate.replace(PROJECT_BASE_DIR.getVariableName(), projectBaseDir);
   return processedTemplate;
 }
    private AskForWorkDir(Project project) {
      super(project);

      setTitle("Set Sphinx Working Directory: ");
      init();
      VirtualFile baseDir = project.getBaseDir();
      String path = baseDir != null ? baseDir.getPath() : "";
      myInputFile.setText(path);
      myInputFile.setEditable(false);
      myInputFile.addBrowseFolderListener(
          "Choose sphinx working directory (containing makefile): ",
          null,
          project,
          FileChooserDescriptorFactory.createSingleFolderDescriptor());

      myPanel.setPreferredSize(new Dimension(600, 20));
    }
  @Nullable
  private static VirtualFile suggestBaseDir(
      @NotNull Project project, final @Nullable VirtualFile file) {
    final VirtualFile[] contentRoots = ProjectRootManager.getInstance(project).getContentRoots();
    if (file == null && contentRoots.length > 0) {
      return contentRoots[0];
    }

    if (file != null) {
      for (VirtualFile contentRoot : contentRoots) {
        if (VfsUtil.isAncestor(contentRoot, file, false)) {
          return contentRoot;
        }
      }
    }

    return project.getBaseDir();
  }