Java Code Examples for com.intellij.openapi.vfs.VirtualFileSystem

The following examples show how to use com.intellij.openapi.vfs.VirtualFileSystem. 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: reasonml-idea-plugin   Source File: OclProjectJdkWizardStep.java    License: 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
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 3
Source Project: aem-ide-tooling-4-intellij   Source File: IProject.java    License: 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 4
@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 5
Source Project: intellij-haxe   Source File: HaxeClasspathEntry.java    License: 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 6
Source Project: consulo   Source File: FileChangedNotificationProvider.java    License: 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 7
Source Project: consulo   Source File: FileAppearanceServiceImpl.java    License: 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 8
Source Project: reasonml-idea-plugin   Source File: OclProjectJdkWizardStep.java    License: 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 9
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 10
Source Project: intellij-haxe   Source File: HaxeCompilerError.java    License: 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 11
Source Project: consulo   Source File: RootsAsVirtualFilePointers.java    License: 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 12
Source Project: consulo   Source File: TestVirtualFile.java    License: 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 13
Source Project: consulo   Source File: FileRefresher.java    License: 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 14
Source Project: consulo   Source File: ShowFilePathAction.java    License: 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 15
Source Project: consulo   Source File: LightFilePointer.java    License: 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 16
Source Project: consulo   Source File: CoreApplicationEnvironment.java    License: 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 17
Source Project: consulo   Source File: VcsVirtualFile.java    License: 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 18
Source Project: consulo   Source File: AbstractVcsVirtualFile.java    License: 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 Project: consulo   Source File: SynchronizeCurrentFileAction.java    License: 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 Project: reasonml-idea-plugin   Source File: OCamlSdkForm.java    License: MIT License 4 votes vote down vote up
public void createUIComponents(@NotNull Sdk sdk) {
    SdkTypeId sdkType = sdk.getSdkType();
    if (sdkType instanceof OCamlSdkType) {
        m_sdkVersion = sdk.getVersionString();
        m_data = (OCamlSdkAdditionalData) sdk.getSdkAdditionalData();
        if (m_data != null) {
            c_version.setText("Current version is: " + m_data);

            c_forceVersion.setSelected(m_data.isForced());
            c_forceVersion.addItemListener(itemEvent -> c_forceValue.setEnabled(itemEvent.getStateChange() == ItemEvent.SELECTED));

            c_forceValue.setText(m_data.toString());
            c_forceValue.setEnabled(m_data.isForced());

            c_sdkHome.addBrowseFolderListener("Choose Sdk Home Directory: ", null, null, FileChooserDescriptorFactory.createSingleFolderDescriptor());

            c_download.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent mouseEvent) {
                    OCamlSdkAdditionalData odkData = (OCamlSdkAdditionalData) sdk.getSdkAdditionalData();
                    if (odkData != null) {
                        // Download SDK from distribution site
                        LOG.debug("Download SDK", m_data.toString());
                        VirtualFileSystem fileSystem = LocalFileSystem.getInstance();
                        VirtualFile sdkHome = fileSystem.findFileByPath(c_sdkHome.getText().trim());
                        if (sdkHome != null) {
                            Task.WithResult<String, RuntimeException> download = new Task.WithResult<String, RuntimeException>(null, "Download SDK", false) {
                                @Override
                                protected String compute(@NotNull ProgressIndicator indicator) throws RuntimeException {
                                    new SdkDownloader(odkData.getMajor(), odkData.getMinor(), odkData.getPatch(), sdkHome).run(null, indicator);
                                    return sdkHome.getPath();
                                }
                            };
                            String path = ProgressManager.getInstance().run(download);
                            Notifications.Bus.notify(new ORNotification("SDK", "SDK " + odkData + " downloaded to " + path, NotificationType.INFORMATION));
                        }
                    }
                }
            });
        }
    }
}
 
Example 21
Source Project: reasonml-idea-plugin   Source File: OclProjectJdkWizardStep.java    License: 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 22
Source Project: intellij   Source File: BlazeAndroidModelTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public VirtualFileSystem getFileSystem() {
  return fileSystem;
}
 
Example 23
Source Project: p4ic4idea   Source File: IOVirtualFile.java    License: Apache License 2.0 4 votes vote down vote up
@NotNull
@Override
public VirtualFileSystem getFileSystem() {
    return MockVirtualFileSystem.DEFAULT_INSTANCE;
}
 
Example 24
Source Project: p4ic4idea   Source File: MockVirtualFile.java    License: Apache License 2.0 4 votes vote down vote up
@NotNull
@Override
public VirtualFileSystem getFileSystem() {
    return fileSystem;
}
 
Example 25
Source Project: p4ic4idea   Source File: MockVirtualFile.java    License: Apache License 2.0 4 votes vote down vote up
@NotNull
@Override
public VirtualFileSystem getFileSystem() {
    throw new IllegalStateException("not implemented");
}
 
Example 26
Source Project: nosql4idea   Source File: NoSqlDatabaseObjectFile.java    License: Apache License 2.0 4 votes vote down vote up
@NotNull
@Override
public VirtualFileSystem getFileSystem() {
    return NoSqlDatabaseFileSystem.getInstance();
}
 
Example 27
Source Project: Crucible4IDEA   Source File: MockCrucibleSession.java    License: MIT License 4 votes vote down vote up
@Nullable
@Override
protected VirtualFile getLocalPath(@NotNull final Repository repo) {
  return new VirtualFile() {
    @NotNull
    @Override
    public String getName() {
      return repo.getName();
    }

    @NotNull
    @Override
    public VirtualFileSystem getFileSystem() {
      return null;
    }

    @Override
    public String getPath() {
      return null;
    }

    @Override
    public boolean isWritable() {
      return false;
    }

    @Override
    public boolean isDirectory() {
      return false;
    }

    @Override
    public boolean isValid() {
      return false;
    }

    @Override
    public VirtualFile getParent() {
      return null;
    }

    @Override
    public VirtualFile[] getChildren() {
      return new VirtualFile[0];
    }

    @NotNull
    @Override
    public OutputStream getOutputStream(Object requestor, long newModificationStamp, long newTimeStamp) throws IOException {
      return null;
    }

    @NotNull
    @Override
    public byte[] contentsToByteArray() throws IOException {
      return new byte[0];
    }

    @Override
    public long getTimeStamp() {
      return 0;
    }

    @Override
    public long getLength() {
      return 0;
    }

    @Override
    public void refresh(boolean asynchronous, boolean recursive, @Nullable Runnable postRunnable) {
    }

    @Override
    public InputStream getInputStream() throws IOException {
      return null;
    }
  };
}
 
Example 28
Source Project: consulo   Source File: BasePathMacroManager.java    License: 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 29
Source Project: consulo   Source File: Mock.java    License: Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
public VirtualFileSystem getFileSystem() {
  throw new UnsupportedOperationException();
}
 
Example 30
Source Project: consulo   Source File: MockVirtualFileSystem.java    License: Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
public VirtualFileSystem getFileSystem() {
  return MockVirtualFileSystem.this;
}