Java Code Examples for com.intellij.openapi.project.Project#getBasePath()

The following examples show how to use com.intellij.openapi.project.Project#getBasePath() . 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: TranslatingCompilerFilesMonitorImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public int getProjectId(Project project) {
  VirtualFile baseDir = project.getBaseDir();
  if(baseDir == null) {
    throw new IllegalArgumentException("there no base directory: " + project.getBasePath());
  }

  return FileBasedIndex.getFileId(baseDir);
}
 
Example 3
Source File: FreelineUtil.java    From freeline with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * if had init freeline return true
 */
public static boolean hadInitFreeline(Project project) {
    if (project != null) {
        String projectPath = project.getBasePath();
        // freeline directory
        File freelineDir = new File(projectPath, "freeline");
        // freeline.py file
        File freeline_py = new File(projectPath, "freeline.py");
        if (freelineDir.exists() && freeline_py.exists()) {
            return true;
        }
    }
    return false;
}
 
Example 4
Source File: DevMenuPlugin.java    From ReactNativeTools with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent event) {
    Project project = event.getData(PlatformDataKeys.PROJECT);
    String path = project.getBasePath();

    String cmd = "cmd /c adb shell input keyevent 82";

    Utils.sendCommand(path, cmd);
}
 
Example 5
Source File: Utils.java    From Plugin with MIT License 5 votes vote down vote up
public static File fileInstallPathForSpec(GearSpec spec, Project project){
    if (spec != null & project != null){
        //Make local separator for speed
        String pathSeparator = Utils.pathSeparator();

        if (spec.getType().equals(GearSpec.SPEC_TYPE_JAR)){
            return new File(project.getBasePath()+pathSeparator+"Gears"+pathSeparator+"Jars"+pathSeparator+spec.getName()+pathSeparator+spec.getVersion());
        }
        else if (spec.getType().equals(GearSpec.SPEC_TYPE_MODULE)){
            return new File(project.getBasePath()+pathSeparator+"Gears"+pathSeparator+"Modules"+pathSeparator+spec.getName()+pathSeparator+spec.getVersion());
        }
    }

    return null;
}
 
Example 6
Source File: PlatformFrameTitleBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public String getProjectTitle(@Nonnull final Project project) {
  final String basePath = project.getBasePath();
  if (basePath == null) return project.getName();

  if (basePath.equals(project.getName())) {
    return "[" + FileUtil.getLocationRelativeToUserHome(basePath) + "]";
  }
  else {
    return project.getName() + " - [" + FileUtil.getLocationRelativeToUserHome(basePath) + "]";
  }
}
 
Example 7
Source File: RNPathUtil.java    From react-native-console with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Ensure get the config file created.
 * @param project
 * @return config file
 */
private static File initConfigFileDir(Project project) {
    String path = project.getBasePath();
    File ideaFolder = new File(path, _IDEA_DIR);
    if(!ideaFolder.exists()) {
        ideaFolder.mkdirs();
    }
    return new File(path, RN_CONSOLE_FILE);
}
 
Example 8
Source File: VfsEventGenerationHelper.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean shouldScanDirectory(@Nonnull VirtualFile parent, @Nonnull Path child, @Nonnull String childName) {
  if (FileTypeManager.getInstance().isFileIgnored(childName)) return false;
  for (Project openProject : ProjectManager.getInstance().getOpenProjects()) {
    if (ReadAction.compute(() -> ProjectFileIndex.getInstance(openProject).isUnderIgnored(parent))) {
      return false;
    }
    String projectRootPath = openProject.getBasePath();
    if (projectRootPath != null) {
      Path path = Paths.get(projectRootPath);
      if (child.startsWith(path)) return true;
    }
  }
  return false;
}
 
Example 9
Source File: ProjectFileNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a base directory for the specified {@code project}, or {@code null} if it does not exist.
 */
@Nullable
static VirtualFile findBaseDir(@Nullable Project project) {
  if (project == null || project.isDisposed()) return null;
  String path = project.getBasePath();
  return path == null ? null : LocalFileSystem.getInstance().findFileByPath(path);
}
 
Example 10
Source File: RNUtil.java    From react-native-console with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * if had init freeline return true
 */
public static boolean hadInitFreeline(Project project) {
    if (project != null) {
        String projectPath = project.getBasePath();
        // freeline directory
        File freelineDir = new File(projectPath, "freeline");
        // freeline.py file
        File freeline_py = new File(projectPath, "freeline.py");
        if (freelineDir.exists() && freeline_py.exists()) {
            return true;
        }
    }
    return false;
}
 
Example 11
Source File: FastpassUpdater.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
private static Optional<FastpassData> extractFastpassData(Project project) {
  try {
    String path = project.getBasePath();
    if (path != null) {
      Optional<FastpassData> fromBsp = readJsonFile(Paths.get(path, ".bsp", "bloop.json"), BspSettings.class)
        .flatMap(settings -> {
          if (settings.fastpassVersion != null && settings.fastpassProjectName != null) {
            return Optional.of(new FastpassData(settings.fastpassVersion, settings.fastpassProjectName));
          } else {
            return Optional.empty();
          }
        });

      Supplier<Optional<FastpassData>> fromBloopSettings =
        () -> readJsonFile(Paths.get(path, ".bloop", "bloop.settings.json"), BloopSettings.class).flatMap(settings -> {
          Pattern pattern = Pattern.compile("org\\.scalameta:fastpass_2\\.12:(.*)");
          Optional<String> version =
            settings.refreshProjectsCommand.stream().map(pattern::matcher).filter(Matcher::find).map(m -> m.group(1)).findFirst();
          return version.map(fastpassVersion -> {
            String projectName = settings.refreshProjectsCommand.get(settings.refreshProjectsCommand.size() - 1);
            return new FastpassData(fastpassVersion, projectName);
          });
        });

      return fromBsp.map(Optional::of).orElseGet(fromBloopSettings);
    }
  }
  catch (Exception e) {
    LOG.warn("Failed to extract fastpass data from " + project, e);
  }
  return Optional.empty();
}
 
Example 12
Source File: SendCommandPlugin.java    From ReactNativeTools with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent event) {
    Project project = Utils.getProjectByEvent(event);
    String path = project.getBasePath();

    String cmd = showDialog(project);

    Utils.sendCommand(path, "cmd /c start " + cmd);
}
 
Example 13
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;
}
 
Example 14
Source File: AsposeMavenUtil.java    From Aspose.OCR-for-Java with MIT License 4 votes vote down vote up
public static String getPOMXmlFile(Project project) {
    String projectPath = project.getBasePath();
    String projectPOM = projectPath + File.separator + AsposeConstants.MAVEN_POM_XML;
    return projectPOM;
}
 
Example 15
Source File: DvcsUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void addMappingIfSubRoot(@Nonnull Project project, @Nonnull String newRepositoryPath, @Nonnull String vcsName) {
  if (project.getBasePath() != null && FileUtil.isAncestor(project.getBasePath(), newRepositoryPath, true)) {
    ProjectLevelVcsManager manager = ProjectLevelVcsManager.getInstance(project);
    manager.setDirectoryMappings(VcsUtil.addMapping(manager.getDirectoryMappings(), newRepositoryPath, vcsName));
  }
}
 
Example 16
Source File: VcsHelper.java    From azure-devops-intellij with MIT License 4 votes vote down vote up
/**
 * This method creates a RepositoryContext object from the local project context.
 * It works for TF Git or TFVC repositories. Any other type of repo will return null.
 *
 * @param project
 * @return
 */
public static RepositoryContext getRepositoryContext(final Project project) {
    ArgumentHelper.checkNotNull(project, "project");
    try {
        final String projectRootFolder = project.getBasePath();

        // Check the manager first since that's where we cache these things
        //TODO this cache doesn't include the current branch info that could have changed. We should probably only cache stuff for TFVC
        RepositoryContext context = RepositoryContextManager.getInstance().get(projectRootFolder);
        if (context != null) {
            logger.info("getRepositoryContext: cache hit: " + projectRootFolder);
            return context;
        }
        logger.info("getRepositoryContext: cache miss: " + projectRootFolder);

        final ProjectLevelVcsManager projectLevelVcsManager = ProjectLevelVcsManager.getInstance(project);
        // Check for Git, then TFVC
        if (projectLevelVcsManager.checkVcsIsActive(GitVcs.NAME)) {
            // It's Git, so get the repository and remote url to create the context from
            final GitRepository repository = getGitRepository(project);
            if (repository != null && TfGitHelper.isTfGitRepository(repository)) {
                final GitRemote gitRemote = TfGitHelper.getTfGitRemote(repository);
                final String gitRemoteUrl = Objects.requireNonNull(gitRemote.getFirstUrl());
                // TODO: Fix this HACK. There doesn't seem to be a clear way to get the full name of the current branch
                final String branch = GIT_BRANCH_PREFIX + GitBranchUtil.getDisplayableBranchText(repository);
                context = RepositoryContext.createGitContext(projectRootFolder, repository.getRoot().getName(), branch, URI.create(gitRemoteUrl));
            }
        } else if (projectLevelVcsManager.checkVcsIsActive(TFSVcs.TFVC_NAME)) {
            final Workspace workspace = CommandUtils.getPartialWorkspace(project, false);
            if (workspace != null) {
                final String projectName = getTeamProjectFromTfvcServerPath(
                        workspace.getMappings().size() > 0 ? workspace.getMappings().get(0).getServerPath() : null);
                context = RepositoryContext.createTfvcContext(projectRootFolder, workspace.getName(), projectName, workspace.getServerUri());
            }
        }

        if (context != null) {
            RepositoryContextManager.getInstance().add(context);
            return context;
        }
    } catch (Throwable t) {
        // Don't let errors bubble out here, just return null if something goes wrong
        logger.warn("Unable to get repository context for the project.", t);
    }

    logger.info("getRepositoryContext: We couldn't determine the VCS provider, so returning null.");
    return null;
}
 
Example 17
Source File: SettingsManager.java    From Plugin with MIT License 4 votes vote down vote up
private Boolean removeIgnoreEntry(){
    ProjectManager pm = ProjectManager.getInstance();
    targetProjects = pm.getOpenProjects();

    if (targetProjects.length > 0){
        Project project = targetProjects[0];

        //Get ignore file
        File gitignore = new File(project.getBasePath()+ Utils.pathSeparator()+".gitignore");
        File hgignoreFile = new File(project.getBasePath()+ Utils.pathSeparator()+".hgignore");
        File ignoreFile =null;

        //Find valid ignore file
        if (gitignore.exists()){
            ignoreFile = gitignore;
        }
        else if (hgignoreFile.exists()){
            ignoreFile = hgignoreFile;
        }

        if (ignoreFile != null){
            try {
                //Read back ignore file
                String ignoreFileString = FileUtils.readFileToString(ignoreFile);

                //remove entry
                ignoreFileString = ignoreFileString.replace(IGNORE_COMMENT_STRING, "");
                ignoreFileString = ignoreFileString.replace(IGNORE_CONTENT_STRING, "");

                //Write back changes to gitignore
                FileUtils.forceDelete(ignoreFile);
                FileUtils.write(ignoreFile, ignoreFileString);
            } catch (IOException e) {
                e.printStackTrace();
                return false;
            }
        }
        else {
            if (createIgnore(ignoreFile)){
                return true;
            }
        }
    }

    return true;
}
 
Example 18
Source File: ShareProject.java    From floobits-intellij with Apache License 2.0 4 votes vote down vote up
public void actionPerformed(AnActionEvent actionEvent, Project project, FloobitsPlugin plugin, ContextImpl context) {
    final String project_path = project.getBasePath();
    FloobitsPlugin.getInstance(project).context.shareProject(false, project_path);
}
 
Example 19
Source File: GearSpecManager.java    From Plugin with MIT License 4 votes vote down vote up
public static Boolean uninstallModule(GearSpec spec, Project project, Module module){

        //Update settings files
        //This MUST be run before removing the physical module on disk. Otherwise, the directory structure for the module may be retained after syncing
        if (!updateProjectSettingsForModule(spec, project, module)){
            return false;
        }

        //Make local path separator for speed
        String pathSeparator = Utils.pathSeparator();

        File libsDirectory = new File(project.getBasePath()+ pathSeparator+ "Gears"+ pathSeparator + "Modules"+pathSeparator+spec.getName());
        if (!libsDirectory.exists()){
            //Unregister just in case
            if (GearSpecRegistrar.unregisterGear(spec, project)){
                return true;
            }
            else {
                return false;
            }
        }

        //Get the jar file
        File moduleDirectory = new File(libsDirectory.getAbsolutePath()+pathSeparator+spec.getVersion());

        //Delete the jar
        if (moduleDirectory.exists()){
            try {
                FileUtils.forceDelete(libsDirectory);
            } catch (IOException e) {
                e.printStackTrace();
                return false;
            }
        }

        //Finally, unregister gear
        if (GearSpecRegistrar.unregisterGear(spec, project)){
            return true;
        }
        else {
            return false;
        }
    }
 
Example 20
Source File: FileSelector.java    From JHelper with GNU Lesser General Public License v3.0 4 votes vote down vote up
private RelativePathBrowseListener(FileChooserDescriptor descriptor, Project project) {
	super(descriptor, project);
	basePath = project.getBasePath();
}