Java Code Examples for com.intellij.openapi.project.Project#getBaseDir()
The following examples show how to use
com.intellij.openapi.project.Project#getBaseDir() .
These examples are extracted from open source projects.
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 Project: consulo-unity3d File: Unity3dProjectService.java License: Apache License 2.0 | 6 votes |
@Nullable @RequiredReadAction private static Module findRootModuleImpl(@Nonnull Project project) { VirtualFile baseDir = project.getBaseDir(); if(baseDir == null) { return null; } ModuleManager moduleManager = ModuleManager.getInstance(project); for(Module module : moduleManager.getModules()) { if(baseDir.equals(module.getModuleDir())) { return module; } } return null; }
Example 2
Source Project: consulo File: CreateNewLibraryAction.java License: Apache License 2.0 | 6 votes |
@Nullable public static NewLibraryConfiguration createNewLibraryConfiguration(@Nullable LibraryType type, @Nonnull JComponent parentComponent, @Nonnull Project project) { final NewLibraryConfiguration configuration; final VirtualFile baseDir = project.getBaseDir(); if (type != null) { configuration = type.createNewLibrary(parentComponent, baseDir, project); } else { configuration = LibraryTypeService.getInstance() .createLibraryFromFiles(new DefaultLibraryRootsComponentDescriptor(), parentComponent, baseDir, null, project); } if (configuration == null) return null; return configuration; }
Example 3
Source Project: consulo File: GotoFileCellRenderer.java License: Apache License 2.0 | 6 votes |
@Nullable public static String getRelativePath(final VirtualFile virtualFile, final Project project) { if (project == null) { return virtualFile.getPresentableUrl(); } VirtualFile root = getAnyRoot(virtualFile, project); if (root != null) { return getRelativePathFromRoot(virtualFile, root); } String url = virtualFile.getPresentableUrl(); final VirtualFile baseDir = project.getBaseDir(); if (baseDir != null) { 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; }
Example 4
Source Project: idea-php-advanced-autocomplete File: FileUtil.java License: MIT License | 6 votes |
public static String[] getProjectFiles(Project project) { final List<String> files = new ArrayList<String>(); final VirtualFile projectDirectory = project.getBaseDir(); ProjectFileIndex fileIndex = ProjectFileIndex.SERVICE.getInstance(project); fileIndex.iterateContentUnderDirectory(projectDirectory, file -> { String relativePath = file.getPath().replace(projectDirectory.getPath() + "/", ""); //files.add(file.getName()); if(!file.isDirectory() && !relativePath.startsWith(".idea/")) { files.add(relativePath); } return true; }); return files.toArray(new String[files.size()]); }
Example 5
Source Project: consulo File: PlatformTestCase.java License: Apache License 2.0 | 5 votes |
protected static Module doCreateRealModuleIn(final String moduleName, final Project project) { final VirtualFile baseDir = project.getBaseDir(); assertNotNull(baseDir); final File moduleFile = new File(baseDir.getPath().replace('/', File.separatorChar), moduleName); FileUtil.createIfDoesntExist(moduleFile); myFilesToDelete.add(moduleFile); return WriteAction.compute(() -> { final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(moduleFile); Module module = ModuleManager.getInstance(project).newModule(moduleName, virtualFile.getPath()); module.getModuleDir(); return module; }); }
Example 6
Source Project: consulo File: ShelvedChange.java License: Apache License 2.0 | 5 votes |
@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); }
Example 7
Source Project: flutter-intellij File: FlutterExternalIdeActionGroup.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
protected static boolean isWithinIOsDirectory(@NotNull VirtualFile file, @NotNull Project project) { final VirtualFile baseDir = project.getBaseDir(); if (baseDir == null) { return false; } VirtualFile candidate = file; while (candidate != null && !baseDir.equals(candidate)) { if (isIOsDirectory(candidate)) { return true; } candidate = candidate.getParent(); } return false; }
Example 8
Source Project: consulo File: ChangesUtil.java License: Apache License 2.0 | 5 votes |
@javax.annotation.Nullable public static String getProjectRelativePath(@Nonnull Project project, @Nullable File fileName) { if (fileName == null) return null; VirtualFile baseDir = project.getBaseDir(); if (baseDir == null) return fileName.toString(); String relativePath = FileUtil.getRelativePath(VfsUtilCore.virtualToIoFile(baseDir), fileName); if (relativePath != null) return relativePath; return fileName.toString(); }
Example 9
Source Project: flutter-intellij File: FlutterExternalIdeActionGroup.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
protected static boolean isWithinAndroidDirectory(@NotNull VirtualFile file, @NotNull Project project) { final VirtualFile baseDir = project.getBaseDir(); if (baseDir == null) { return false; } VirtualFile candidate = file; while (candidate != null && !baseDir.equals(candidate)) { if (isAndroidDirectory(candidate)) { return true; } candidate = candidate.getParent(); } return false; }
Example 10
Source Project: consulo File: PatternDescriptor.java License: Apache License 2.0 | 5 votes |
@Nonnull private static String getRelativePath(@Nonnull Project project, @Nullable VirtualFile parent) { VirtualFile projectDir = project.getBaseDir(); String projectPath = projectDir.getPath(); if (parent != null) { String parentPath = parent.getPath(); if (parentPath.startsWith(projectPath)) { return parentPath.substring(projectPath.length()); } else { return parentPath; } } return ""; }
Example 11
Source Project: idea-php-advanced-autocomplete File: FileUtil.java License: MIT License | 5 votes |
public static String[] getRelativeFiles(PsiFile baseFile) { final List<String> files = new ArrayList<String>(); Project project = baseFile.getProject(); final VirtualFile projectDirectory = project.getBaseDir(); PsiDirectory directory = baseFile.getContainingDirectory(); if(directory == null) return null; final VirtualFile originDirectory = directory.getVirtualFile(); ProjectFileIndex fileIndex = ProjectFileIndex.SERVICE.getInstance(project); /* for(VirtualFile file : originDirectory.getChildren()) { files.add(file.getPath().replace(projectDirectory.getPath() + "/", "")); } */ fileIndex.iterateContentUnderDirectory(originDirectory, new ContentIterator() { @Override public boolean processFile(VirtualFile file) { //files.add(file.getName()); if(!file.isDirectory()) { files.add(file.getPath().replace(originDirectory.getPath() + "/", "")); } return true; } } ); return files.toArray(new String[files.size()]); }
Example 12
Source Project: aem-ide-tooling-4-intellij File: FolderSelectionDialog.java License: Apache License 2.0 | 5 votes |
public FolderSelectionDialog(@NotNull Project project) { super(project); setTitle(AEMBundle.message("dialog.aemdc.files.parent.title")); this.project = project; this.baseDir = project.getBaseDir(); setModal(true); setUpDialog(); init(); }
Example 13
Source Project: consulo File: FileChooserUtil.java License: Apache License 2.0 | 5 votes |
@Nullable public static VirtualFile getFileToSelect(@Nonnull FileChooserDescriptor descriptor, @Nullable Project project, @Nullable VirtualFile toSelect, @Nullable VirtualFile lastPath) { boolean chooseDir = descriptor instanceof FileSaverDescriptor; VirtualFile result; if (toSelect == null && lastPath == null) { result = project == null? null : project.getBaseDir(); } else if (toSelect != null && lastPath != null) { if (Boolean.TRUE.equals(descriptor.getUserData(PathChooserDialog.PREFER_LAST_OVER_EXPLICIT))) { result = lastPath; } else { result = toSelect; } } else if (toSelect == null) { result = lastPath; } else { result = toSelect; } if (result != null) { if (chooseDir && !result.isDirectory()) { result = result.getParent(); } } else if (SystemInfo.isUnix) { result = VfsUtil.getUserHomeDir(); } return result; }
Example 14
Source Project: consulo File: ProjectKt.java License: Apache License 2.0 | 5 votes |
@Nullable public static VirtualFile getDirectoryStoreFile(Project project) { VirtualFile baseDir = project.getBaseDir(); if(baseDir == null) { return null; } return baseDir.findChild(Project.DIRECTORY_STORE_FOLDER); }
Example 15
Source Project: Buck-IntelliJ-Plugin File: BuckBuildManager.java License: Apache License 2.0 | 5 votes |
public boolean isBuckProject(Project project) { if (project == null) { return false; } VirtualFile base = project.getBaseDir(); return base.findChild(BuckBuildUtil.BUCK_CONFIG_FILE) != null; }
Example 16
Source Project: consulo File: ProjectFileDirectoryRule.java License: Apache License 2.0 | 5 votes |
@Override public VirtualFile getData(@Nonnull DataProvider dataProvider) { VirtualFile dir = dataProvider.getDataUnchecked(PlatformDataKeys.PROJECT_FILE_DIRECTORY); if (dir == null) { final Project project = dataProvider.getDataUnchecked(CommonDataKeys.PROJECT); if (project != null) { dir = project.getBaseDir(); } } return dir; }
Example 17
Source Project: buck File: BuckBuildManager.java License: Apache License 2.0 | 5 votes |
public boolean isBuckProject(Project project) { if (project == null) { return false; } VirtualFile base = project.getBaseDir(); return base.findChild(BuckBuildUtil.BUCK_CONFIG_FILE) != null; }
Example 18
Source Project: android-codegenerator-plugin-intellij File: ProjectHelper.java License: Apache License 2.0 | 5 votes |
private VirtualFile createFolderIfNotExist(Project project, String folder) throws IOException { VirtualFile directory = project.getBaseDir(); String[] folders = folder.split("/"); for (String childFolder : folders) { VirtualFile childDirectory = directory.findChild(childFolder); if (childDirectory != null && childDirectory.isDirectory()) { directory = childDirectory; } else { directory = directory.createChildDirectory(project, childFolder); } } return directory; }
Example 19
Source Project: consulo File: FileRelativePathMacro.java License: Apache License 2.0 | 5 votes |
@Override public String expand(DataContext dataContext) { Project project = dataContext.getData(CommonDataKeys.PROJECT); final VirtualFile baseDir = project == null ? null : project.getBaseDir(); if (baseDir == null) { return null; } VirtualFile file = dataContext.getData(PlatformDataKeys.VIRTUAL_FILE); if (file == null) return null; return FileUtil.getRelativePath(VfsUtil.virtualToIoFile(baseDir), VfsUtil.virtualToIoFile(file)); }
Example 20
Source Project: consulo File: ProjectViewProjectNode.java License: Apache License 2.0 | 4 votes |
@RequiredReadAction @Override @Nonnull public Collection<AbstractTreeNode> getChildren() { List<VirtualFile> topLevelContentRoots = BaseProjectViewDirectoryHelper.getTopLevelRoots(myProject); Set<Module> modules = new LinkedHashSet<>(topLevelContentRoots.size()); Project project = getProject(); for (VirtualFile root : topLevelContentRoots) { final Module module = ModuleUtil.findModuleForFile(root, project); if (module != null) { // Some people exclude module's content roots... modules.add(module); } } ArrayList<AbstractTreeNode> nodes = new ArrayList<>(); final PsiManager psiManager = PsiManager.getInstance(project); nodes.addAll(modulesAndGroups(modules.toArray(new Module[modules.size()]))); final VirtualFile baseDir = project.getBaseDir(); if (baseDir == null) return nodes; final VirtualFile[] files = baseDir.getChildren(); for (VirtualFile file : files) { if (ModuleUtil.findModuleForFile(file, project) == null) { if (!file.isDirectory()) { PsiFile psiFile = psiManager.findFile(file); if(psiFile != null) { nodes.add(new PsiFileNode(project, psiFile, getSettings())); } } } } if (getSettings().isShowLibraryContents()) { nodes.add(new ExternalLibrariesNode(project, getSettings())); } return nodes; }