Java Code Examples for com.intellij.openapi.project.Project#DIRECTORY_STORE_FOLDER

The following examples show how to use com.intellij.openapi.project.Project#DIRECTORY_STORE_FOLDER . 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: IMWindowFactory.java    From SmartIM4IntelliJ with Apache License 2.0 6 votes vote down vote up
public File getWorkDir() {
    Project p = this.project;
    if (p == null) {
        p = ProjectManager.getInstance().getDefaultProject();
        Project[] ps = ProjectManager.getInstance().getOpenProjects();
        if (ps != null) {
            for (Project t : ps) {
                if (!t.isDefault()) {
                    p = t;
                }
            }
        }
    }
    File dir = new File(p.getBasePath(), Project.DIRECTORY_STORE_FOLDER);
    return dir;
}
 
Example 2
Source File: ProjectStoreImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void setProjectFilePath(@Nonnull final String filePath) {
  final StateStorageManager stateStorageManager = getStateStorageManager();
  final LocalFileSystem fs = LocalFileSystem.getInstance();

  final File file = new File(filePath);

  final File dirStore = file.isDirectory() ? new File(file, Project.DIRECTORY_STORE_FOLDER) : new File(file.getParentFile(), Project.DIRECTORY_STORE_FOLDER);
  String defaultFilePath = new File(dirStore, "misc.xml").getPath();
  // deprecated
  stateStorageManager.addMacro(StoragePathMacros.PROJECT_FILE, defaultFilePath);
  stateStorageManager.addMacro(StoragePathMacros.DEFAULT_FILE, defaultFilePath);

  final File ws = new File(dirStore, "workspace.xml");
  stateStorageManager.addMacro(StoragePathMacros.WORKSPACE_FILE, ws.getPath());

  stateStorageManager.addMacro(StoragePathMacros.PROJECT_CONFIG_DIR, dirStore.getPath());

  ApplicationManager.getApplication().invokeAndWait(() -> VfsUtil.markDirtyAndRefresh(false, true, true, fs.refreshAndFindFileByIoFile(dirStore)), ModalityState.defaultModalityState());

  myPresentableUrl = null;
}
 
Example 3
Source File: ProjectStoreImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void setProjectFilePathNoUI(@Nonnull final String filePath) {
  final StateStorageManager stateStorageManager = getStateStorageManager();
  final LocalFileSystem fs = LocalFileSystem.getInstance();

  final File file = new File(filePath);

  final File dirStore = file.isDirectory() ? new File(file, Project.DIRECTORY_STORE_FOLDER) : new File(file.getParentFile(), Project.DIRECTORY_STORE_FOLDER);
  String defaultFilePath = new File(dirStore, "misc.xml").getPath();
  // deprecated
  stateStorageManager.addMacro(StoragePathMacros.PROJECT_FILE, defaultFilePath);
  stateStorageManager.addMacro(StoragePathMacros.DEFAULT_FILE, defaultFilePath);

  final File ws = new File(dirStore, "workspace.xml");
  stateStorageManager.addMacro(StoragePathMacros.WORKSPACE_FILE, ws.getPath());

  stateStorageManager.addMacro(StoragePathMacros.PROJECT_CONFIG_DIR, dirStore.getPath());

  VfsUtil.markDirtyAndRefresh(false, true, true, fs.refreshAndFindFileByIoFile(dirStore));

  myPresentableUrl = null;
}
 
Example 4
Source File: ProjectWrangler.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void cleanUpProjectForImport(@NotNull File projectPath) {
  File dotIdeaFolderPath = new File(projectPath, Project.DIRECTORY_STORE_FOLDER);
  if (dotIdeaFolderPath.isDirectory()) {
    File modulesXmlFilePath = new File(dotIdeaFolderPath, "modules.xml");
    if (modulesXmlFilePath.isFile()) {
      SAXBuilder saxBuilder = new SAXBuilder();
      try {
        Document document = saxBuilder.build(modulesXmlFilePath);
        XPath xpath = XPath.newInstance("//*[@fileurl]");
        //noinspection unchecked
        List<Element> modules = xpath.selectNodes(document);
        int urlPrefixSize = "file://$PROJECT_DIR$/".length();
        for (Element module : modules) {
          String fileUrl = module.getAttributeValue("fileurl");
          if (!StringUtil.isEmpty(fileUrl)) {
            String relativePath = toSystemDependentName(fileUrl.substring(urlPrefixSize));
            File imlFilePath = new File(projectPath, relativePath);
            if (imlFilePath.isFile()) {
              FileUtilRt.delete(imlFilePath);
            }
            // It is likely that each module has a "build" folder. Delete it as well.
            File buildFilePath = new File(imlFilePath.getParentFile(), "build");
            if (buildFilePath.isDirectory()) {
              FileUtilRt.delete(buildFilePath);
            }
          }
        }
      }
      catch (Throwable ignored) {
        // if something goes wrong, just ignore. Most likely it won't affect project import in any way.
      }
    }
    FileUtilRt.delete(dotIdeaFolderPath);
  }
}
 
Example 5
Source File: ProjectStoreImplIdeaDirTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected File getTempProjectDir() throws IOException {
  final File projectDir = FileUtil.createTempDirectory(getTestName(true), "project");
  File ideaDir = new File(projectDir, Project.DIRECTORY_STORE_FOLDER);
  assertTrue(ideaDir.mkdir() || ideaDir.isDirectory());
  File iprFile = new File(ideaDir, "misc.xml");
  FileUtil.writeToFile(iprFile, getIprFileContent());

  myFilesToDelete.add(projectDir);
  return projectDir;
}
 
Example 6
Source File: ProjectStoreImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static String readProjectName(@Nonnull File file) {
  if (file.isDirectory()) {
    final File nameFile = new File(new File(file, Project.DIRECTORY_STORE_FOLDER), ProjectImpl.NAME_FILE);
    if (nameFile.exists()) {
      try {
        return FileUtil.loadFile(nameFile, true);
      }
      catch (IOException ignored) {
      }
    }
  }
  return file.getName();
}
 
Example 7
Source File: ProjectOrModuleNameStep.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean validateNameAndPath(@Nonnull NewModuleWizardContext context) throws WizardStepValidationException {
  final String name = myNamePathComponent.getNameValue();
  if (name.length() == 0) {
    final ApplicationInfo info = ApplicationInfo.getInstance();
    throw new WizardStepValidationException(IdeBundle.message("prompt.new.project.file.name", info.getVersionName(), context.getTargetId()));
  }

  final String projectFileDirectory = myNamePathComponent.getPath();
  if (projectFileDirectory.length() == 0) {
    throw new WizardStepValidationException(IdeBundle.message("prompt.enter.project.file.location", context.getTargetId()));
  }

  final boolean shouldPromptCreation = myNamePathComponent.isPathChangedByUser();
  if (!ProjectWizardUtil.createDirectoryIfNotExists(IdeBundle.message("directory.project.file.directory", context.getTargetId()), projectFileDirectory, shouldPromptCreation)) {
    return false;
  }

  final File file = new File(projectFileDirectory);
  if (file.exists() && !file.canWrite()) {
    throw new WizardStepValidationException(String.format("Directory '%s' is not writable!\nPlease choose another project location.", projectFileDirectory));
  }

  boolean shouldContinue = true;
  final File projectDir = new File(myNamePathComponent.getPath(), Project.DIRECTORY_STORE_FOLDER);
  if (projectDir.exists()) {
    int answer = Messages
            .showYesNoDialog(IdeBundle.message("prompt.overwrite.project.folder", projectDir.getAbsolutePath(), context.getTargetId()), IdeBundle.message("title.file.already.exists"), Messages.getQuestionIcon());
    shouldContinue = (answer == Messages.YES);
  }

  return shouldContinue;
}
 
Example 8
Source File: NamePathComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
public boolean validateNameAndPath(@Nonnull NewModuleWizardContext context) throws ConfigurationException {
  final String name = getNameValue();
  if (name.length() == 0) {
    final ApplicationInfo info = ApplicationInfo.getInstance();
    throw new ConfigurationException(IdeBundle.message("prompt.new.project.file.name", info.getVersionName(), context.getTargetId()));
  }

  final String projectFileDirectory = getPath();
  if (projectFileDirectory.length() == 0) {
    throw new ConfigurationException(IdeBundle.message("prompt.enter.project.file.location", context.getTargetId()));
  }

  final boolean shouldPromptCreation = isPathChangedByUser();
  if (!ProjectWizardUtil.createDirectoryIfNotExists(IdeBundle.message("directory.project.file.directory", context.getTargetId()), projectFileDirectory, shouldPromptCreation)) {
    return false;
  }

  final File file = new File(projectFileDirectory);
  if (file.exists() && !file.canWrite()) {
    throw new ConfigurationException(String.format("Directory '%s' is not writable!\nPlease choose another project location.", projectFileDirectory));
  }

  boolean shouldContinue = true;
  final File projectDir = new File(getPath(), Project.DIRECTORY_STORE_FOLDER);
  if (projectDir.exists()) {
    int answer = Messages.showYesNoDialog(IdeBundle.message("prompt.overwrite.project.folder", projectDir.getAbsolutePath(), context.getTargetId()), IdeBundle.message("title.file.already.exists"),
                                          Messages.getQuestionIcon());
    shouldContinue = (answer == Messages.YES);
  }

  return shouldContinue;
}
 
Example 9
Source File: NewOrImportModuleUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@RequiredUIAccess
public static <T extends ModuleImportContext> AsyncResult<Project> importProject(@Nonnull T context, @Nonnull ModuleImportProvider<T> importProvider) {
  final ProjectManagerEx projectManager = ProjectManagerEx.getInstanceEx();
  final String projectFilePath = context.getPath();
  String projectName = context.getName();

  try {
    File projectDir = new File(projectFilePath);
    FileUtil.ensureExists(projectDir);
    File projectConfigDir = new File(projectDir, Project.DIRECTORY_STORE_FOLDER);
    FileUtil.ensureExists(projectConfigDir);

    final Project newProject = projectManager.createProject(projectName, projectFilePath);

    if (newProject == null) return AsyncResult.rejected();

    newProject.save();

    ModifiableModuleModel modifiableModel = ModuleManager.getInstance(newProject).getModifiableModel();

    importProvider.process(context, newProject, modifiableModel, module -> {
    });

    WriteAction.runAndWait(modifiableModel::commit);

    newProject.save();

    context.dispose();

    return AsyncResult.resolved(newProject);
  }
  catch (Exception e) {
    context.dispose();

    return AsyncResult.<Project>undefined().rejectWithThrowable(e);
  }
}
 
Example 10
Source File: BlazeProjectCreator.java    From intellij with Apache License 2.0 4 votes vote down vote up
private void doCreate() throws IOException {
  String projectFilePath = wizardContext.getProjectFileDirectory();

  File projectDir = new File(projectFilePath).getParentFile();
  logger.assertTrue(
      projectDir != null,
      "Cannot create project in '" + projectFilePath + "': no parent file exists");
  FileUtil.ensureExists(projectDir);
  if (wizardContext.getProjectStorageFormat() == StorageScheme.DIRECTORY_BASED) {
    final File ideaDir = new File(projectFilePath, Project.DIRECTORY_STORE_FOLDER);
    FileUtil.ensureExists(ideaDir);
  }

  String name = wizardContext.getProjectName();
  Project newProject = projectBuilder.createProject(name, projectFilePath);
  if (newProject == null) {
    return;
  }

  if (!ApplicationManager.getApplication().isUnitTestMode()) {
    newProject.save();
  }

  if (!projectBuilder.validate(null, newProject)) {
    return;
  }

  projectBuilder.commit(newProject, null, ModulesProvider.EMPTY_MODULES_PROVIDER);

  StartupManager.getInstance(newProject)
      .registerPostStartupActivity(
          () -> {
            // ensure the dialog is shown after all startup activities are done
            //noinspection SSBasedInspection
            SwingUtilities.invokeLater(
                () -> {
                  if (newProject.isDisposed()
                      || ApplicationManager.getApplication().isUnitTestMode()) {
                    return;
                  }
                  ApplicationManager.getApplication()
                      .invokeLater(
                          () -> {
                            if (newProject.isDisposed()) {
                              return;
                            }
                            final ToolWindow toolWindow =
                                ToolWindowManager.getInstance(newProject)
                                    .getToolWindow(ToolWindowId.PROJECT_VIEW);
                            if (toolWindow != null) {
                              toolWindow.activate(null);
                            }
                          },
                          ModalityState.NON_MODAL);
                });
          });

  ProjectUtil.updateLastProjectLocation(projectFilePath);

  if (WindowManager.getInstance().isFullScreenSupportedInCurrentOS()) {
    IdeFocusManager instance = IdeFocusManager.findInstance();
    IdeFrame lastFocusedFrame = instance.getLastFocusedFrame();
    if (lastFocusedFrame instanceof IdeFrameEx) {
      boolean fullScreen = ((IdeFrameEx) lastFocusedFrame).isInFullScreen();
      if (fullScreen) {
        newProject.putUserData(IdeFrameImpl.SHOULD_OPEN_IN_FULL_SCREEN, Boolean.TRUE);
      }
    }
  }

  BaseSdkCompat.openProject(newProject, Paths.get(projectFilePath));

  if (!ApplicationManager.getApplication().isUnitTestMode()) {
    SaveAndSyncHandler.getInstance().scheduleProjectSave(newProject);
  }
}
 
Example 11
Source File: StorageUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static String getStoreDir(@Nonnull Project project) {
  return project.getBasePath() + "/" + Project.DIRECTORY_STORE_FOLDER;
}