本文整理了Java中com.intellij.openapi.project.Project.getBaseDir()
方法的一些代码示例,展示了Project.getBaseDir()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Project.getBaseDir()
方法的具体详情如下:
包路径:com.intellij.openapi.project.Project
类名称:Project
方法名:getBaseDir
暂无
代码示例来源:origin: ballerina-platform/ballerina-lang
@Nullable
public static VirtualFile findByPath(@NotNull String path, @NotNull Project project) {
String systemIndependentPath = FileUtil.toSystemIndependentName(path);
VirtualFile projectBaseDir = project.getBaseDir();
if (systemIndependentPath.isEmpty()) {
return projectBaseDir;
}
return projectBaseDir.findFileByRelativePath(systemIndependentPath);
}
}
代码示例来源:origin: hsz/idea-gitignore
/**
* Checks if file is in project directory.
*
* @param file file
* @param project project
* @return file is under directory
*/
public static boolean isInProject(@NotNull final VirtualFile file, @NotNull final Project project) {
return project.getBaseDir() != null && (isUnder(file, project.getBaseDir()) ||
StringUtil.startsWith(file.getUrl(), "temp://"));
}
代码示例来源:origin: hsz/idea-gitignore
/**
* Returns fixed directory for the given {@link IgnoreLanguage}.
*
* @param project current project
* @return fixed directory
*/
@Nullable
@Override
public VirtualFile getFixedDirectory(@NotNull Project project) {
return project.getBaseDir().findFileByRelativePath(getVcsDirectory() + "/info");
}
}
代码示例来源:origin: ballerina-platform/ballerina-lang
private static String readConfig(@NotNull Project project, @Nullable String defaultValue,
@NotNull Pattern pattern) {
VirtualFile baseDir = project.getBaseDir();
VirtualFile relativeFile = VfsUtilCore.findRelativeFile(BallerinaConstants.BALLERINA_CONFIG_FILE_NAME, baseDir);
if (relativeFile == null) {
return defaultValue;
}
try (InputStream inputStream = relativeFile.getInputStream()) {
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String line;
while ((line = bufferedReader.readLine()) != null) {
Matcher matcher = pattern.matcher(line.trim());
if (matcher.find()) {
return matcher.group(1);
}
}
bufferedReader.close();
inputStreamReader.close();
} catch (IOException e) {
// Ignore errors
}
return defaultValue;
}
}
代码示例来源:origin: hsz/idea-gitignore
@NotNull
@Override
public Collection<VirtualFile> fetch(@NotNull Project project) {
final Collection<VirtualFile> files = ContainerUtil.newArrayList();
final VirtualFile baseDir = project.getBaseDir();
if (baseDir == null) {
return files;
}
final VirtualFile root = baseDir.findChild(".git");
return processExcludes(root, files);
}
代码示例来源:origin: ballerina-platform/ballerina-lang
private static List<VirtualFile> getPackagesFromProject(@NotNull Project project) {
List<VirtualFile> packages = ContainerUtil.newArrayList();
VirtualFile projectBaseDir = project.getBaseDir();
VirtualFile[] children = projectBaseDir.getChildren();
for (VirtualFile child : children) {
// If the child is not a directory or the name starts with ".", we ignore it.
if (!child.isDirectory() || child.getName().startsWith(".")) {
continue;
}
packages.add(child);
}
return packages;
}
代码示例来源:origin: hsz/idea-gitignore
/**
* Shows action in the context menu if current file is covered by the specified {@link #ignoreFile}.
*
* @param e action event
*/
@Override
public void update(@NotNull AnActionEvent e) {
final VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
final Project project = e.getProject();
if (project == null || files == null || (files.length == 1 && files[0].equals(project.getBaseDir()))) {
e.getPresentation().setVisible(false);
}
}
代码示例来源:origin: hsz/idea-gitignore
/**
* Returns all Ignore files in given {@link Project} that can match current passed file.
*
* @param project current project
* @param file current file
* @return collection of suitable Ignore files
*/
public static List<VirtualFile> getSuitableIgnoreFiles(@NotNull Project project, @NotNull IgnoreFileType fileType,
@NotNull VirtualFile file)
throws ExternalFileException {
List<VirtualFile> files = ContainerUtil.newArrayList();
if (file.getCanonicalPath() == null || project.getBaseDir() == null ||
!VfsUtilCore.isAncestor(project.getBaseDir(), file, true)) {
throw new ExternalFileException();
}
VirtualFile baseDir = project.getBaseDir();
if (baseDir != null && !baseDir.equals(file)) {
do {
file = file.getParent();
VirtualFile ignoreFile = file.findChild(fileType.getIgnoreLanguage().getFilename());
ContainerUtil.addIfNotNull(files, ignoreFile);
} while (!file.equals(project.getBaseDir()));
}
return files;
}
代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin
public static void installFileChooser(@NotNull Project project,
@NotNull ComponentWithBrowseButton field,
boolean directory,
boolean showFileSystemRoots,
@Nullable Condition<VirtualFile> fileFilter) {
FileChooserDescriptor chooseDirectoryDescriptor = directory
? FileChooserDescriptorFactory.createSingleFolderDescriptor()
: FileChooserDescriptorFactory.createSingleLocalFileDescriptor();
chooseDirectoryDescriptor.setRoots(project.getBaseDir());
chooseDirectoryDescriptor.setShowFileSystemRoots(showFileSystemRoots);
chooseDirectoryDescriptor.withFileFilter(fileFilter);
if (field instanceof TextFieldWithBrowseButton) {
((TextFieldWithBrowseButton)field).addBrowseFolderListener(new TextBrowseFolderListener(chooseDirectoryDescriptor, project));
}
else {
//noinspection unchecked
field.addBrowseFolderListener(project, new ComponentWithBrowseButton.BrowseFolderActionListener(null, null, field, project,
chooseDirectoryDescriptor,
TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT));
}
}
代码示例来源:origin: hsz/idea-gitignore
/** {@link IgnoreLanguage} is a non-instantiable static class. */
private FossilLanguage() {
super("Fossil", "ignore-glob", ".fossil-settings", Icons.FOSSIL, new OuterFileFetcher[]{
// Outer file fetched from the .fossil-settings/ignore-glob file.
project -> {
final VirtualFile baseDir = project.getBaseDir();
return ContainerUtil.createMaybeSingletonList(baseDir == null ? null : baseDir
.findFileByRelativePath(INSTANCE.getVcsDirectory() + "/" + INSTANCE.getFilename()));
}
});
}
代码示例来源:origin: go-lang-plugin-org/go-lang-idea-plugin
VirtualFile baseDir = myProject.getBaseDir();
if (baseDir != null) {
virtualFile = baseDir.findFileByRelativePath(fileName);
代码示例来源:origin: hsz/idea-gitignore
@Override
public void visitEntry(@NotNull IgnoreEntry entry) {
final VirtualFile baseDir = project.getBaseDir();
if (content.contains(entry.getText()) && baseDir != null) {
Notify.show(
project,
IgnoreBundle.message("action.appendFile.entryExists", entry.getText()),
IgnoreBundle.message(
"action.appendFile.entryExists.in",
Utils.getRelativePath(baseDir, file.getVirtualFile())
),
NotificationType.WARNING
);
content.remove(entry.getText());
}
}
});
代码示例来源:origin: hsz/idea-gitignore
@Nullable
public static VirtualFile getWorkingDirectory(@NotNull Project project, @NotNull VirtualFile outerFile) {
final VirtualFile baseDir = project.getBaseDir();
final VirtualFile infoDir = baseDir.findFileByRelativePath(".git/info");
if (infoDir != null && Utils.isUnder(outerFile, infoDir)) {
return baseDir;
}
final VirtualFile gitModules = baseDir.findFileByRelativePath(".git/modules");
if (gitModules != null && Utils.isUnder(outerFile, gitModules)) {
String path = Utils.getRelativePath(gitModules, outerFile.getParent().getParent());
if (path != null) {
return baseDir.findFileByRelativePath(path);
}
}
return null;
}
}
代码示例来源:origin: ballerina-platform/ballerina-lang
private static void installFileChooser(@NotNull Project project, @NotNull ComponentWithBrowseButton field,
@Nullable Condition<VirtualFile> fileFilter) {
FileChooserDescriptor chooseDirectoryDescriptor =
FileChooserDescriptorFactory.createSingleFileDescriptor(BallerinaFileType.INSTANCE);
chooseDirectoryDescriptor.setRoots(project.getBaseDir());
chooseDirectoryDescriptor.setShowFileSystemRoots(false);
chooseDirectoryDescriptor.withShowHiddenFiles(false);
chooseDirectoryDescriptor.withFileFilter(fileFilter);
if (field instanceof TextFieldWithBrowseButton) {
((TextFieldWithBrowseButton) field).addBrowseFolderListener(
new TextBrowseFolderListener(chooseDirectoryDescriptor, project));
} else {
//noinspection unchecked
field.addBrowseFolderListener(project, new ComponentWithBrowseButton.BrowseFolderActionListener(null,
null, field, project, chooseDirectoryDescriptor,
TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT));
}
}
代码示例来源:origin: ballerina-platform/ballerina-lang
String fileName = myFrame.getFileName();
Project project = myProcess.getSession().getProject();
String projectBasePath = project.getBaseDir().getPath();
代码示例来源:origin: hsz/idea-gitignore
/**
* Constructor.
*
* @param project current project
* @param files files map to present
*/
public UntrackFilesDialog(@NotNull Project project, @NotNull ConcurrentMap<VirtualFile, VcsRoot> files) {
super(project, false);
this.project = project;
this.files = files;
this.root = createDirectoryNodes(project.getBaseDir(), null);
setTitle(IgnoreBundle.message("dialog.untrackFiles.title"));
setOKButtonText(IgnoreBundle.message("global.ok"));
setCancelButtonText(IgnoreBundle.message("global.cancel"));
init();
}
代码示例来源:origin: hsz/idea-gitignore
/**
* Gets Ignore file for given {@link Project} and root {@link PsiDirectory}.
* If file is missing - creates new one.
*
* @param project current project
* @param fileType current ignore file type
* @param directory root directory
* @param createIfMissing create new file if missing
* @return Ignore file
*/
@Nullable
public static PsiFile getIgnoreFile(@NotNull Project project, @NotNull IgnoreFileType fileType,
@Nullable PsiDirectory directory, boolean createIfMissing) {
if (directory == null) {
directory = PsiManager.getInstance(project).findDirectory(project.getBaseDir());
}
assert directory != null;
String filename = fileType.getIgnoreLanguage().getFilename();
PsiFile file = directory.findFile(filename);
VirtualFile virtualFile = file == null ? directory.getVirtualFile().findChild(filename) : file.getVirtualFile();
if (file == null && virtualFile == null && createIfMissing) {
try {
file = new CreateFileCommandAction(project, directory, fileType).execute();
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
return file;
}
代码示例来源:origin: hsz/idea-gitignore
/**
* Presents a list of suitable Gitignore files that can cover currently selected {@link VirtualFile}.
* Shows a subgroup with available files or one option if only one Gitignore file is available.
*
* @param e action event
*/
@Override
public void update(@NotNull AnActionEvent e) {
final VirtualFile file = e.getData(CommonDataKeys.VIRTUAL_FILE);
final Project project = e.getData(CommonDataKeys.PROJECT);
final Presentation presentation = e.getPresentation();
files.clear();
if (project != null && file != null) {
try {
presentation.setVisible(true);
baseDir = project.getBaseDir();
for (IgnoreLanguage language : IgnoreBundle.LANGUAGES) {
final IgnoreFileType fileType = language.getFileType();
List<VirtualFile> list = Utils.getSuitableIgnoreFiles(project, fileType, file);
Collections.reverse(list);
files.put(fileType, list);
}
} catch (ExternalFileException e1) {
presentation.setVisible(false);
}
}
setPopup(countFiles() > 1);
}
代码示例来源:origin: hsz/idea-gitignore
final VirtualFile parent = element.getContainingFile().getVirtualFile().getParent();
final Project project = element.getProject();
final VirtualFile projectDir = project.getBaseDir();
if (parent == null || projectDir == null || !Utils.isUnder(parent, projectDir)) {
return null;
代码示例来源:origin: hsz/idea-gitignore
/**
* {@link IgnoreManager.TrackedIgnoredListener} method implementation to handle incoming files.
*
* @param files tracked and ignored files list
*/
@Override
public void handleFiles(@NotNull final ConcurrentMap<VirtualFile, VcsRoot> files) {
if (!settings.isInformTrackedIgnored() || notificationShown || myProject.getBaseDir() == null) {
return;
}
notificationShown = true;
Notify.show(
myProject,
IgnoreBundle.message("notification.untrack.title", Utils.getVersion()),
IgnoreBundle.message("notification.untrack.content"),
NotificationType.INFORMATION,
(notification, event) -> {
if (DISABLE_ACTION.equals(event.getDescription())) {
settings.setInformTrackedIgnored(false);
} else if (!myProject.isDisposed()) {
new UntrackFilesDialog(myProject, files).show();
}
notification.expire();
}
);
}
}
内容来源于网络,如有侵权,请联系作者删除!