com.intellij.openapi.vfs.StandardFileSystems Java Examples

The following examples show how to use com.intellij.openapi.vfs.StandardFileSystems. 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: BlazeLibrary.java    From intellij with Apache License 2.0 6 votes vote down vote up
protected static String pathToUrl(File path) {
  String name = path.getName();
  boolean isJarFile =
      FileUtilRt.extensionEquals(name, "jar")
          || FileUtilRt.extensionEquals(name, "srcjar")
          || FileUtilRt.extensionEquals(name, "zip");
  // .jar files require an URL with "jar" protocol.
  String protocol =
      isJarFile
          ? StandardFileSystems.JAR_PROTOCOL
          : VirtualFileSystemProvider.getInstance().getSystem().getProtocol();
  String filePath = FileUtil.toSystemIndependentName(path.getPath());
  String url = VirtualFileManager.constructUrl(protocol, filePath);
  if (isJarFile) {
    url += URLUtil.JAR_SEPARATOR;
  }
  return url;
}
 
Example #2
Source File: GraphQLTreeNodeNavigationUtil.java    From js-graphql-intellij-plugin with MIT License 6 votes vote down vote up
public static void openSourceLocation(Project myProject, SourceLocation location, boolean resolveSDLFromJSON) {
    VirtualFile sourceFile = StandardFileSystems.local().findFileByPath(location.getSourceName());
    if (sourceFile != null) {
        PsiFile file = PsiManager.getInstance(myProject).findFile(sourceFile);
        if (file != null) {
            if (file instanceof JsonFile && resolveSDLFromJSON) {
                GraphQLFile graphQLFile = file.getUserData(GraphQLSchemaKeys.GRAPHQL_INTROSPECTION_JSON_TO_SDL);
                if (graphQLFile != null) {
                    // open the SDL file and not the JSON introspection file it was based on
                    file = graphQLFile;
                    sourceFile = file.getVirtualFile();
                }
            }
            new OpenFileDescriptor(myProject, sourceFile, location.getLine() - 1, location.getColumn() - 1).navigate(true);
        }
    }
}
 
Example #3
Source File: ModuleManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@Nonnull
public Module newModule(@Nonnull @NonNls String name, @Nullable @NonNls String dirPath) {
  assertWritable();

  final String dirUrl = dirPath == null ? null : VirtualFileManager.constructUrl(StandardFileSystems.FILE_PROTOCOL, dirPath);

  ModuleEx moduleEx = null;
  if (dirUrl != null) {
    moduleEx = getModuleByDirUrl(dirUrl);
  }

  if (moduleEx == null) {
    moduleEx = createModule(name, dirUrl, null);
    initModule(moduleEx);
  }
  return moduleEx;
}
 
Example #4
Source File: PersistentFSTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void testFindRootShouldNotBeFooledByRelativePath() throws IOException {
  File tmp = createTempDirectory();
  File x = new File(tmp, "x.jar");
  x.createNewFile();
  LocalFileSystem lfs = LocalFileSystem.getInstance();
  VirtualFile vx = lfs.refreshAndFindFileByIoFile(x);
  assertNotNull(vx);
  ArchiveFileSystem jfs = (ArchiveFileSystem)StandardFileSystems.jar();
  VirtualFile root = ArchiveVfsUtil.getArchiveRootForLocalFile(vx);

  PersistentFS fs = PersistentFS.getInstance();

  String path = vx.getPath() + "/../" + vx.getName() + ArchiveFileSystem.ARCHIVE_SEPARATOR;
  NewVirtualFile root1 = fs.findRoot(path, (NewVirtualFileSystem)jfs);

  assertSame(root1, root);
}
 
Example #5
Source File: SdkImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public VirtualFile getHomeDirectory() {
  if (myHomePath == null) {
    return null;
  }
  return StandardFileSystems.local().findFileByPath(myHomePath);
}
 
Example #6
Source File: ExternalSystemUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static VirtualFile findLocalFileByPath(String path) {
  VirtualFile result = StandardFileSystems.local().findFileByPath(path);
  if (result != null) return result;

  return !Application.get().isReadAccessAllowed() ? findLocalFileByPathUnderWriteAction(path) : findLocalFileByPathUnderReadAction(path);
}
 
Example #7
Source File: LightFilePointer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static String toPresentableUrl(@Nonnull String url) {
  String path = VirtualFileManager.extractPath(url);
  String protocol = VirtualFileManager.extractProtocol(url);
  VirtualFileSystem fileSystem = VirtualFileManager.getInstance().getFileSystem(protocol);
  return ObjectUtils.notNull(fileSystem, StandardFileSystems.local()).extractPresentableUrl(path);
}
 
Example #8
Source File: Unity3dPackageOrderEntry.java    From consulo-unity3d with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
@RequiredReadAction
public String[] getUrls(@Nonnull OrderRootType rootType)
{
	List<String> urls = new SmartList<>();

	if(rootType == BinariesOrderRootType.getInstance() || rootType == SourcesOrderRootType.getInstance())
	{
		// moved to project files
		String projectPackageCache = getProjectPackageCache();
		if(new File(projectPackageCache, myNameWithVersion).exists())
		{
			urls.add(StandardFileSystems.FILE_PROTOCOL_PREFIX + FileUtil.toSystemIndependentName(projectPackageCache + "/" + myNameWithVersion));
		}

		if(urls.isEmpty())
		{
			Unity3dPackageWatcher watcher = Unity3dPackageWatcher.getInstance();
			for(String path : watcher.getPackageDirPaths())
			{
				if(new File(path, myNameWithVersion).exists())
				{
					urls.add(StandardFileSystems.FILE_PROTOCOL_PREFIX + FileUtil.toSystemIndependentName(path + "/" + myNameWithVersion));
				}
			}
		}
	}

	if(urls.isEmpty())
	{
		Sdk sdk = getSdk();
		if(sdk != null)
		{
			String builtInPath = sdk.getHomePath() + "/" + getBuiltInPackagesRelativePath();
			String packageName = getPackageName();
			if(new File(builtInPath, packageName).exists())
			{
				urls.add(StandardFileSystems.FILE_PROTOCOL_PREFIX + FileUtil.toSystemIndependentName(builtInPath + "/" + packageName));
			}
		}
	}

	return ArrayUtil.toStringArray(urls);
}
 
Example #9
Source File: MSBaseDotNetCompilerOptionsBuilder.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example #10
Source File: BasePathMacroManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static VirtualFileSystem getLocalFileSystem() {
  // Use VFM directly because of mocks in tests.
  return VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL);
}
 
Example #11
Source File: ExternalSystemUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
private static VirtualFile findLocalFileByPathUnderWriteAction(final String path) {
  return ExternalSystemApiUtil.doWriteAction(() -> StandardFileSystems.local().refreshAndFindFileByPath(path));
}
 
Example #12
Source File: ExternalSystemUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
private static VirtualFile findLocalFileByPathUnderReadAction(final String path) {
  return ReadAction.compute(() -> StandardFileSystems.local().findFileByPath(path));
}
 
Example #13
Source File: CoreLocalFileSystem.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public String getProtocol() {
  return StandardFileSystems.FILE_PROTOCOL;
}
 
Example #14
Source File: CoreJarFileSystem.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public String getProtocol() {
  return StandardFileSystems.JAR_PROTOCOL;
}