Java Code Examples for com.intellij.openapi.util.io.FileUtil#isAbsolute()
The following examples show how to use
com.intellij.openapi.util.io.FileUtil#isAbsolute() .
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: ContainerFile.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Nullable public File getFile(Project project) { if (!FileUtil.isAbsolute(this.path)) { VirtualFile virtualFile = VfsUtil.findRelativeFile(this.path, ProjectUtil.getProjectDir(project)); if(virtualFile == null) { return null; } return VfsUtil.virtualToIoFile(virtualFile); } File file = new File(this.path); if(!file.exists()) { return null; } return file; }
Example 2
Source File: ProgramParametersConfigurator.java From consulo with Apache License 2.0 | 6 votes |
@Nullable public String getWorkingDir(CommonProgramRunConfigurationParameters configuration, Project project, Module module) { String workingDirectory = configuration.getWorkingDirectory(); String defaultWorkingDir = getDefaultWorkingDir(project); if (StringUtil.isEmptyOrSpaces(workingDirectory)) { workingDirectory = defaultWorkingDir; if (workingDirectory == null) { return null; } } workingDirectory = expandPath(workingDirectory, module, project); if (!FileUtil.isAbsolute(workingDirectory) && defaultWorkingDir != null) { if (("$" + PathMacroUtil.MODULE_DIR_MACRO_NAME + "$").equals(workingDirectory)) { return defaultWorkingDir; } if (module != null && MODULE_WORKING_DIR.equals(workingDirectory)) { String workingDir = getDefaultWorkingDir(module); if (workingDir != null) return workingDir; } workingDirectory = defaultWorkingDir + "/" + workingDirectory; } return workingDirectory; }
Example 3
Source File: TestFileSystem.java From intellij with Apache License 2.0 | 5 votes |
/** * Absolute file paths are prohibited -- the TempDirTestFixture used in these tests will prepend * it's own root to the path. */ private String makePathRelativeToTestFixture(String filePath) { if (!FileUtil.isAbsolute(filePath)) { return filePath; } String tempDirPath = getRootDir(); assertWithMessage( String.format( "Invalid absolute file path. '%s' is not underneath the test file system root '%s'", filePath, tempDirPath)) .that(FileUtil.isAncestor(tempDirPath, filePath, true)) .isTrue(); return FileUtil.getRelativePath(tempDirPath, filePath, File.separatorChar); }
Example 4
Source File: EnvCompositePart.java From p4ic4idea with Apache License 2.0 | 5 votes |
@Nullable private VirtualFile getRelFile(@NotNull String path) { if (FileUtil.isAbsolute(path)) { return LocalFileSystem.getInstance().findFileByPath(path); } return getFileAt(vcsRoot.getPath(), path); }
Example 5
Source File: PantsLibrariesExtension.java From intellij-pants-plugin with Apache License 2.0 | 5 votes |
private void addPathLoLibrary( @NotNull LibraryData libraryData, @NotNull PantsCompileOptionsExecutor executor, @NotNull LibraryPathType binary, @Nullable String path ) { if (path == null) { return; } path = FileUtil.isAbsolute(path) ? path : executor.getAbsolutePathFromWorkingDir(path); if (new File(path).exists()) { libraryData.addPath(binary, path); } }
Example 6
Source File: HaxeFileUtil.java From intellij-haxe with Apache License 2.0 | 5 votes |
/** * Determine whether a path/url is an absolute file name. * * @param path path to test * @return true if the path is absolute */ public static boolean isAbsolutePath(@Nullable String path) { if (null == path || path.isEmpty()) { return false; } String stripped = VirtualFileManager.getInstance().extractPath(path); return (FileUtil.isAbsolute(stripped)); }
Example 7
Source File: RouteHelper.java From idea-php-symfony2-plugin with MIT License | 5 votes |
private static String getPath(Project project, String path) { if (!FileUtil.isAbsolute(path)) { // Project relative path path = project.getBasePath() + "/" + path; } return path; }
Example 8
Source File: TwigPath.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Nullable public String getRelativePath(@NotNull Project project) { if(!FileUtil.isAbsolute(path)) { return path; } VirtualFile virtualFile = getDirectory(); if(virtualFile == null) { return null; } return VfsUtil.getRelativePath(virtualFile, ProjectUtil.getProjectDir(project), '/'); }
Example 9
Source File: TwigPath.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Nullable public VirtualFile getDirectory(@NotNull Project project) { if(!FileUtil.isAbsolute(path)) { return VfsUtil.findRelativeFile(path, ProjectUtil.getProjectDir(project)); } else { VirtualFile fileByIoFile = VfsUtil.findFileByIoFile(new File(path), true); if(fileByIoFile != null) { return fileByIoFile; } } return null; }
Example 10
Source File: AbstractUiFilePath.java From idea-php-symfony2-plugin with MIT License | 5 votes |
public boolean exists(@NotNull Project project) { if (!FileUtil.isAbsolute(this.path)) { return VfsUtil.findRelativeFile(this.path, ProjectUtil.getProjectDir(project)) != null; } return new File(this.path).exists(); }
Example 11
Source File: TranslationIndex.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@NotNull private Collection<File> getTranslationRootInner() { Collection<File> files = new HashSet<>(); String translationPath = Settings.getInstance(project).pathToTranslation; if (StringUtils.isNotBlank(translationPath)) { if (!FileUtil.isAbsolute(translationPath)) { translationPath = project.getBasePath() + "/" + translationPath; } File file = new File(translationPath); if(file.exists() && file.isDirectory()) { files.add(file); } } VirtualFile baseDir = ProjectUtil.getProjectDir(project); for (String containerFile : ServiceContainerUtil.getContainerFiles(project)) { // resolve the file VirtualFile containerVirtualFile = VfsUtil.findRelativeFile(containerFile, baseDir); if (containerVirtualFile == null) { continue; } // get directory of the file; translation folder is same directory VirtualFile cacheDirectory = containerVirtualFile.getParent(); if (cacheDirectory == null) { continue; } // get translation sub directory VirtualFile translations = cacheDirectory.findChild("translations"); if (translations != null) { files.add(VfsUtilCore.virtualToIoFile(translations)); } } return files; }
Example 12
Source File: FilesystemUtil.java From idea-php-symfony2-plugin with MIT License | 5 votes |
/** * Try to find an "app" directory on configuration or on project directory in root * We also support absolute path in configuration */ @NotNull public static Collection<VirtualFile> getAppDirectories(@NotNull Project project) { Collection<VirtualFile> virtualFiles = new HashSet<>(); // find "app" folder on user settings String directoryToApp = Settings.getInstance(project).directoryToApp; if(FileUtil.isAbsolute(directoryToApp)) { // absolute dir given VirtualFile fileByIoFile = VfsUtil.findFileByIoFile(new File(directoryToApp), true); if(fileByIoFile != null) { virtualFiles.add(fileByIoFile); } } else { // relative path resolve VirtualFile globalDirectory = VfsUtil.findRelativeFile( ProjectUtil.getProjectDir(project), directoryToApp.replace("\\", "/").split("/") ); if(globalDirectory != null) { virtualFiles.add(globalDirectory); } } // global "app" in root VirtualFile templates = VfsUtil.findRelativeFile(ProjectUtil.getProjectDir(project), "app"); if(templates != null) { virtualFiles.add(templates); } return virtualFiles; }
Example 13
Source File: TreeModelBuilder.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private static StaticFilePath staticFrom(@Nonnull FilePath fp) { final String path = fp.getPath(); if (fp.isNonLocal() && (!FileUtil.isAbsolute(path) || VcsUtil.isPathRemote(path))) { return new StaticFilePath(fp.isDirectory(), fp.getIOFile().getPath().replace('\\', '/'), fp.getVirtualFile()); } return new StaticFilePath(fp.isDirectory(), new File(fp.getIOFile().getPath().replace('\\', '/')).getAbsolutePath(), fp.getVirtualFile()); }
Example 14
Source File: MSBaseDotNetCompilerOptionsBuilder.java From consulo-csharp with Apache License 2.0 | 4 votes |
@Override public DotNetCompilerMessage convertToMessage(Module module, String line) { if(line.startsWith("error")) { return new DotNetCompilerMessage(CompilerMessageCategory.ERROR, line, null, -1, 1); } else { Matcher matcher = LINE_ERROR_PATTERN.matcher(line); if(matcher.matches()) { CompilerMessageCategory category = CompilerMessageCategory.INFORMATION; if(matcher.group(4).equals("error")) { category = CompilerMessageCategory.ERROR; } else if(matcher.group(4).equals("warning")) { category = CompilerMessageCategory.WARNING; } String fileUrl = FileUtil.toSystemIndependentName(matcher.group(1)); if(!FileUtil.isAbsolute(fileUrl)) { fileUrl = module.getModuleDirUrl() + "/" + fileUrl; } else { fileUrl = VirtualFileManager.constructUrl(StandardFileSystems.FILE_PROTOCOL, fileUrl); } int codeLine = Integer.parseInt(matcher.group(2)); int codeColumn = Integer.parseInt(matcher.group(3)); String message = matcher.group(6); if(ApplicationProperties.isInSandbox()) { message += "(" + matcher.group(5) + ")"; } return new DotNetCompilerMessage(category, message, fileUrl, codeLine, codeColumn - 1); } } return null; }