com.intellij.openapi.vfs.VirtualFileSystem Java Examples

The following examples show how to use com.intellij.openapi.vfs.VirtualFileSystem. 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: OclProjectJdkWizardStep.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
@Override
public boolean validate() throws ConfigurationException {
    VirtualFileSystem fileSystem = LocalFileSystem.getInstance();

    VirtualFile sdkHome = fileSystem.findFileByPath(c_sdkHome.getText().trim());
    if (sdkHome == null) {
        throw new ConfigurationException("Can't find sdk home directory, make sure it exists");
    }
    if (!sdkHome.isDirectory()) {
        throw new ConfigurationException("Sdk home is not a directory");
    }
    if (!sdkHome.isWritable()) {
        throw new ConfigurationException("sdk home is not writable");
    }

    return super.validate();
}
 
Example #2
Source File: FileAppearanceServiceImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public CellAppearanceEx forVirtualFile(@Nonnull final VirtualFile file) {
  if (!file.isValid()) {
    return forInvalidUrl(file.getPresentableUrl());
  }

  final VirtualFileSystem fileSystem = file.getFileSystem();
  if (fileSystem instanceof ArchiveFileSystem) {
    return new JarSubfileCellAppearance(file);
  }
  if (fileSystem instanceof HttpFileSystem) {
    return new HttpUrlCellAppearance(file);
  }
  if (file.isDirectory()) {
    return SimpleTextCellAppearance.regular(file.getPresentableUrl(), AllIcons.Nodes.Folder);
  }
  return new ValidFileCellAppearance(file);
}
 
Example #3
Source File: FileChangedNotificationProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@Nonnull VirtualFile file, @Nonnull FileEditor fileEditor) {
  if (!myProject.isDisposed() && !GeneralSettings.getInstance().isSyncOnFrameActivation()) {
    VirtualFileSystem fs = file.getFileSystem();
    if (fs instanceof LocalFileSystem) {
      FileAttributes attributes = ((LocalFileSystem)fs).getAttributes(file);
      if (attributes == null || file.getTimeStamp() != attributes.lastModified || file.getLength() != attributes.length) {
        LogUtil.debug(LOG, "%s: (%s,%s) -> %s", file, file.getTimeStamp(), file.getLength(), attributes);
        return createPanel(file);
      }
    }
  }

  return null;
}
 
Example #4
Source File: HaxeClasspathEntry.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
public HaxeClasspathEntry(@Nullable String name, @NotNull String url) {
  myName = name;
  myUrl = url;

  // Try to fix the URL if it wasn't correct.
  if (!url.contains(URLUtil.SCHEME_SEPARATOR)) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Fixing malformed URL passed by " + HaxeDebugUtil.printCallers(5));
    }
    VirtualFileSystem vfs = VirtualFileManager.getInstance().getFileSystem(LocalFileSystem.PROTOCOL);
    VirtualFile file = vfs.findFileByPath(url);
    if (null != file) {
      myUrl = file.getUrl();
    }
  }

  if (null != myName) {
    if (HaxelibNameUtil.isManagedLibrary(myName)) {
      myName = HaxelibNameUtil.parseHaxelib(myName);
      myIsManagedEntry = true;
    }
  }
}
 
Example #5
Source File: CSharpCreateFromTemplateHandler.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Nullable
@RequiredReadAction
public static Module findModuleByPsiDirectory(final PsiDirectory directory)
{
	LightVirtualFile l = new LightVirtualFile("test.cs", CSharpFileType.INSTANCE, "")
	{
		@Override
		public VirtualFile getParent()
		{
			return directory.getVirtualFile();
		}

		@Nonnull
		@Override
		public VirtualFileSystem getFileSystem()
		{
			return LocalFileSystem.getInstance();
		}
	};
	return CreateFileFromTemplateAction.ModuleResolver.EP_NAME.composite().resolveModule(directory, CSharpFileType.INSTANCE);
}
 
Example #6
Source File: IProject.java    From aem-ide-tooling-4-intellij with Apache License 2.0 6 votes vote down vote up
public IFolder getFolder(IPath path) {
    com.headwire.aem.tooling.intellij.communication.MessageManager messageManager = ComponentProvider.getComponent(project,
        com.headwire.aem.tooling.intellij.communication.MessageManager.class
    );
    messageManager.sendDebugNotification("debug.folder.path", path);

    String filePath = path.toOSString();

    messageManager.sendDebugNotification("debug.folder.os.path", filePath);

    VirtualFileSystem vfs = module.getProject().getBaseDir().getFileSystem();
    VirtualFile file = vfs.findFileByPath(path.toOSString());
    if(file != null) {
        return new IFolder(module, file);
    } else {
        return new IFolder(module, new File(path.toOSString()));
    }
}
 
Example #7
Source File: ResourcesPlugin.java    From aem-ide-tooling-4-intellij with Apache License 2.0 6 votes vote down vote up
public IResource findMember(IPath childPath) {
    // I guess we need to figure out if that file is part of the project and if so return an IResource
    DataContext dataContext = DataManager.getInstance().getDataContextFromFocus().getResult();
    VirtualFile file = null;
    if(dataContext != null) {
        Project project = CommonDataKeys.PROJECT.getData(dataContext);
        String aPath = childPath.toOSString();
        VirtualFileSystem vfs = project.getProjectFile().getFileSystem();
        file = vfs.findFileByPath(aPath);
    } else {
        String message = "could not obtain data context";
    }
    //AS TODO: If this is only used as a marker then we are fine but otherwise we need to obtain the current module
    return file == null ? null :
        (file.isDirectory() ? new IFolder() : new IFile());
}
 
Example #8
Source File: SlingProject4IntelliJ.java    From aem-ide-tooling-4-intellij with Apache License 2.0 5 votes vote down vote up
public SlingProject4IntelliJ(ServerConfiguration.Module module) {
    logger.debug("Getting Started, Module: " + module);
    this.module = module;
    Project project = module.getProject();
    VirtualFileSystem vfs = project.getBaseDir().getFileSystem();
    for(String path: module.getUnifiedModule().getContentDirectoryPaths()) {
        if(Util.pathEndsWithFolder(path, JCR_ROOT_FOLDER_NAME)) {
            File folder = new File(path);
            if(folder.exists() && folder.isDirectory()) {
                syncDirectory = new SlingResource4IntelliJ(this, vfs.findFileByPath(path));
                break;
            }
        }
    }
}
 
Example #9
Source File: TestVirtualFile.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public VirtualFileSystem getFileSystem() {
  return new MockLocalFileSystem() {
    @Override
    public boolean equals(Object o) {
      return true;
    }
  };
}
 
Example #10
Source File: FileRefresher.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Starts watching the specified file, which was added before.
 *
 * @param file      a file to watch
 * @param recursive {@code true} if a file should be considered as root
 * @return an object that allows to stop watching the specified file
 */
protected Object watch(VirtualFile file, boolean recursive) {
  VirtualFileSystem fs = file.getFileSystem();
  if (fs instanceof LocalFileSystem) {
    return LocalFileSystem.getInstance().addRootToWatch(file.getPath(), recursive);
  }
  return null;
}
 
Example #11
Source File: ShowFilePathAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static VirtualFile findLocalFile(@Nullable VirtualFile file) {
  if (file == null) return null;

  if (file.isInLocalFileSystem()) {
    return file;
  }

  VirtualFileSystem fs = file.getFileSystem();
  if (fs instanceof ArchiveFileSystem && file.getParent() == null) {
    return ((ArchiveFileSystem)fs).getLocalVirtualFileFor(file);
  }

  return null;
}
 
Example #12
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 #13
Source File: CoreApplicationEnvironment.java    From consulo with Apache License 2.0 5 votes vote down vote up
public CoreApplicationEnvironment(@Nonnull Disposable parentDisposable) {
  myParentDisposable = parentDisposable;

  myFileTypeRegistry = new CoreFileTypeRegistry();

  myApplication = createApplication(myParentDisposable);
  ApplicationManager.setApplication(myApplication, myParentDisposable);
  myLocalFileSystem = createLocalFileSystem();
  myJarFileSystem = createJarFileSystem();

  final InjectingContainer appContainer = myApplication.getInjectingContainer();
  registerComponentInstance(appContainer, FileDocumentManager.class, new MockFileDocumentManagerImpl(DocumentImpl::new, null));

  VirtualFileSystem[] fs = {myLocalFileSystem, myJarFileSystem};
  VirtualFileManagerImpl virtualFileManager = new VirtualFileManagerImpl(myApplication, fs);
  registerComponentInstance(appContainer, VirtualFileManager.class, virtualFileManager);

  registerApplicationExtensionPoint(ASTLazyFactory.EP.getExtensionPointName(), ASTLazyFactory.class);
  registerApplicationExtensionPoint(ASTLeafFactory.EP.getExtensionPointName(), ASTLeafFactory.class);
  registerApplicationExtensionPoint(ASTCompositeFactory.EP.getExtensionPointName(), ASTCompositeFactory.class);

  addExtension(ASTLazyFactory.EP.getExtensionPointName(), new DefaultASTLazyFactory());
  addExtension(ASTLeafFactory.EP.getExtensionPointName(), new DefaultASTLeafFactory());
  addExtension(ASTCompositeFactory.EP.getExtensionPointName(), new DefaultASTCompositeFactory());

  registerApplicationService(EncodingManager.class, new CoreEncodingRegistry());
  registerApplicationService(VirtualFilePointerManager.class, createVirtualFilePointerManager());
  registerApplicationService(PsiBuilderFactory.class, new PsiBuilderFactoryImpl());
  registerApplicationService(ReferenceProvidersRegistry.class, new MockReferenceProvidersRegistry());
  registerApplicationService(StubTreeLoader.class, new CoreStubTreeLoader());
  registerApplicationService(PsiReferenceService.class, new PsiReferenceServiceImpl());
  registerApplicationService(MetaDataRegistrar.class, new MetaRegistry());

  registerApplicationService(ProgressManager.class, createProgressIndicatorProvider());

  registerApplicationService(JobLauncher.class, createJobLauncher());
  registerApplicationService(CodeFoldingSettings.class, new CodeFoldingSettings());
  registerApplicationService(CommandProcessor.class, new CoreCommandProcessor());
}
 
Example #14
Source File: RootsAsVirtualFilePointers.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void setNoCopyJars(@Nonnull String url) {
  String protocol = VirtualFileManager.extractProtocol(url);
  if (protocol == null) {
    return;
  }

  VirtualFileSystem fs = VirtualFileManager.getInstance().getFileSystem(protocol);
  if (fs instanceof ArchiveFileSystem) {
    ((ArchiveFileSystem)fs).addNoCopyArchiveForPath(url);
  }
}
 
Example #15
Source File: VcsVirtualFile.java    From consulo with Apache License 2.0 5 votes vote down vote up
public VcsVirtualFile(@Nonnull String path,
                      @Nonnull byte[] content,
                      @javax.annotation.Nullable String revision,
                      @Nonnull VirtualFileSystem fileSystem) {
  this(path, null, fileSystem);
  myContent = content;
  setRevision(revision);
}
 
Example #16
Source File: HaxeCompilerError.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
public String getUrl() {

    VirtualFileSystem vfs = VirtualFileManager.getInstance().getFileSystem(LocalFileSystem.PROTOCOL);
    VirtualFile file = vfs.findFileByPath(getPath());

    StringBuilder msg = new StringBuilder(file.getUrl());
    msg.append('#');
    msg.append(getLine());
    msg.append(':');
    msg.append(getColumn());
    return msg.toString();
  }
 
Example #17
Source File: OclProjectJdkWizardStep.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
private void addSdkSources(@NotNull SdkModificator odkModificator, @NotNull File targetSdkLocation) throws IOException {
    VirtualFileSystem fileSystem = LocalFileSystem.getInstance();

    Files.walkFileTree(targetSdkLocation.toPath(), new SimpleFileVisitor<Path>() {
        @NotNull
        @Override
        public FileVisitResult visitFile(@NotNull Path path, BasicFileAttributes basicFileAttributes) {
            VirtualFile file = fileSystem.findFileByPath(path.toString());
            if (file != null) {
                odkModificator.addRoot(file, OCamlSourcesOrderRootType.getInstance());
            }
            return FileVisitResult.CONTINUE;
        }
    });
}
 
Example #18
Source File: AbstractVcsVirtualFile.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected AbstractVcsVirtualFile(String path, VirtualFileSystem fileSystem) {
  myFileSystem = fileSystem;
  myPath = path;
  File file = new File(myPath);
  myName = file.getName();
  if (!isDirectory())
    myParent = new VcsVirtualFolder(file.getParent(), this, myFileSystem);
  else
    myParent = null;
}
 
Example #19
Source File: SynchronizeCurrentFileAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  final Project project = getEventProject(e);
  final VirtualFile[] files = getFiles(e);
  if (project == null || files == null || files.length == 0) return;

  CallChain.first(UIAccess.current()).linkWrite(() -> {
    for (VirtualFile file : files) {
      final VirtualFileSystem fs = file.getFileSystem();
      if (fs instanceof LocalFileSystem && file instanceof NewVirtualFile) {
        ((NewVirtualFile)file).markDirtyRecursively();
      }
    }
  }).linkUI(() -> {
    final Runnable postRefreshAction = () -> {
      final VcsDirtyScopeManager dirtyScopeManager = VcsDirtyScopeManager.getInstance(project);
      for (VirtualFile f : files) {
        if (f.isDirectory()) {
          dirtyScopeManager.dirDirtyRecursively(f);
        }
        else {
          dirtyScopeManager.fileDirty(f);
        }
      }

      final StatusBar statusBar = WindowManager.getInstance().getStatusBar(project);
      if (statusBar != null) {
        final String message = IdeBundle.message("action.sync.completed.successfully", getMessage(files));
        statusBar.setInfo(message);
      }
    };

    RefreshQueue.getInstance().refresh(true, true, postRefreshAction, files);
  }).toss();
}
 
Example #20
Source File: VcsVirtualFile.java    From consulo with Apache License 2.0 4 votes vote down vote up
public VcsVirtualFile(@Nonnull String path,
                      @Nullable VcsFileRevision revision,
                      @Nonnull VirtualFileSystem fileSystem) {
  super(path, fileSystem);
  myFileRevision = revision;
}
 
Example #21
Source File: CoreApplicationEnvironment.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public VirtualFileSystem getJarFileSystem() {
  return myJarFileSystem;
}
 
Example #22
Source File: CoreApplicationEnvironment.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
protected VirtualFileSystem createJarFileSystem() {
  return new CoreJarFileSystem();
}
 
Example #23
Source File: AbstractVcsVirtualFile.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public VirtualFileSystem getFileSystem() {
  return myFileSystem;
}
 
Example #24
Source File: CoreJarVirtualFile.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public VirtualFileSystem getFileSystem() {
  return myHandler.getFileSystem();
}
 
Example #25
Source File: CoreLocalVirtualFile.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public VirtualFileSystem getFileSystem() {
  return myFileSystem;
}
 
Example #26
Source File: CoreLocalVirtualFile.java    From consulo with Apache License 2.0 4 votes vote down vote up
public CoreLocalVirtualFile(@Nonnull VirtualFileSystem fileSystem, @Nonnull File ioFile) {
  myFileSystem = fileSystem;
  myIoFile = ioFile;
  isDirectory = ioFile.isDirectory();
}
 
Example #27
Source File: VcsVirtualFolder.java    From consulo with Apache License 2.0 4 votes vote down vote up
public VcsVirtualFolder(String name, VirtualFile child, VirtualFileSystem fileSystem) {
  super(name == null ? "" : name, fileSystem);
  myChild = child;
}
 
Example #28
Source File: OclProjectJdkWizardStep.java    From reasonml-idea-plugin with MIT License 4 votes vote down vote up
@Override
public void onWizardFinished() throws CommitStepException {
    Sdk odk = null;

    if (c_rdSelectExisting.isSelected()) {
        JdkComboBox.JdkComboBoxItem selectedItem = c_selExistingSdk.getSelectedItem();
        odk = selectedItem == null ? null : selectedItem.getJdk();
    } else if (c_rdDownloadSdk.isSelected()) {
        String selectedSdk = (String) c_selDownload.getSelectedItem();
        String sdkHomeValue = PropertiesComponent.getInstance().getValue(SDK_HOME);
        if (sdkHomeValue != null) {
            VirtualFileSystem fileSystem = LocalFileSystem.getInstance();
            VirtualFile sdkHome = fileSystem.findFileByPath(sdkHomeValue);

            if (selectedSdk != null && sdkHome != null) {
                int pos = selectedSdk.lastIndexOf('.');
                String patch = selectedSdk.substring(pos + 1);
                String majorMinor = selectedSdk.substring(0, pos);
                pos = majorMinor.lastIndexOf('.');
                String major = majorMinor.substring(0, pos);
                String minor = majorMinor.substring(pos + 1);

                // Download SDK from distribution site
                LOG.debug("Download SDK", selectedSdk);
                ProgressManager.getInstance().run(SdkDownloader.modalTask(major, minor, patch, sdkHome, m_context.getProject()));

                // Create SDK
                LOG.debug("Create SDK", selectedSdk);
                File targetSdkLocation = new File(sdkHome.getCanonicalPath(), "ocaml-" + selectedSdk);
                odk = SdkConfigurationUtil.createAndAddSDK(targetSdkLocation.getAbsolutePath(), new OCamlSdkType());
                if (odk != null) {
                    SdkModificator odkModificator = odk.getSdkModificator();

                    odkModificator.setVersionString(selectedSdk);  // must be set after home path, otherwise setting home path clears the version string
                    odkModificator.setName("OCaml (sources only) " + major);
                    try {
                        addSdkSources(odkModificator, targetSdkLocation);
                    } catch (IOException e) {
                        throw new CommitStepException(e.getMessage());
                    }

                    odkModificator.commitChanges();
                }
            }
        }
    }

    // update selected sdk in builder
    ProjectBuilder builder = m_context.getProjectBuilder();
    if (odk != null && builder instanceof DuneProjectImportBuilder) {
        ((DuneProjectImportBuilder) builder).setModuleSdk(odk);
    }
}
 
Example #29
Source File: VirtualFileImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
public VirtualFileSystem getFileSystem() {
  return myFileSystem;
}
 
Example #30
Source File: VirtualFileImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
public VirtualFileSystem getFileSystem() {
  return myFileSystem;
}