@NotNull @Override public CellAppearanceEx forVirtualFile(@NotNull final VirtualFile file) { if (!file.isValid()) { return forInvalidUrl(file.getPresentableUrl()); } final VirtualFileSystem fileSystem = file.getFileSystem(); if (fileSystem.getProtocol().equals(JarFileSystem.PROTOCOL)) { return new JarSubfileCellAppearance(file); } if (fileSystem instanceof HttpFileSystem) { return new HttpUrlCellAppearance(file); } if (file.isDirectory()) { return SimpleTextCellAppearance.regular(file.getPresentableUrl(), PlatformIcons.FOLDER_ICON); } return new ValidFileCellAppearance(file); }
@Nullable @Override public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull 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; }
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()); }
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())); } }
public static void launchExternalLink(@NotNull final Project project, @NotNull final String href) { if (PathInfo.isExternal(href)) { BrowserUtil.browse(href); } else if (href.startsWith("file://")) { try { URL target = new URL(href); VirtualFileSystem virtualFileSystem = VirtualFileManager.getInstance().getFileSystem(target.getProtocol()); final VirtualFile virtualFile = virtualFileSystem == null ? null : virtualFileSystem.findFileByPath(target.getFile()); // open local file if (virtualFile != null) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { FileEditorManager.getInstance(project).openFile(virtualFile, true, true); // TODO: see if we can resolve the #hashSuffix in the file //logger.info("got hash suffixed href: " + href + "#" + hashSuffix); } }); } } catch (MalformedURLException ignored) { } } }
/** * {@inheritDoc} */ @Override public final VirtualFile unresolve(final FileObject resource) { if (resource instanceof IntelliJFileObject) { final IntelliJFileObject intellijResource = (IntelliJFileObject)resource; try { return intellijResource.asVirtualFile(); } catch (final FileSystemException e) { throw LoggerUtils2.exception(this.logger, UnhandledException.class, "Unexpected exception while resolving file: {}", e, resource); } } final URI uri = toUri(resource.getName().getURI()); @Nullable final VirtualFileSystem fileSystem = getFileSystem(uri); @Nullable final String path = getPath(uri); if (fileSystem == null || path == null) { throw LoggerUtils2.exception(this.logger, IllegalStateException.class, "Can't unresolve this URI: {}", uri); } return fileSystem.refreshAndFindFileByPath(path); }
@Nullable @RequiredReadAction public static Module findModuleByPsiDirectory(final PsiDirectory directory) { LightVirtualFile l = new LightVirtualFile("test.cs", CSharpFileType.INSTANCE, "") { @Override public VirtualFile getParent() { return directory.getVirtualFile(); } @NotNull @Override public VirtualFileSystem getFileSystem() { return LocalFileSystem.getInstance(); } }; return CreateFileFromTemplateAction.ModuleResolver.EP_NAME.composite().resolveModule(directory, CSharpFileType.INSTANCE); }
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; } } }
private static void addNoCopyArchiveForPaths(SdkRoot root) { if (root instanceof SimpleSdkRoot) { String url = ((SimpleSdkRoot)root).getUrl(); String protocolId = VirtualFileManager.extractProtocol(url); VirtualFileSystem fileSystem = VirtualFileManager.getInstance().getFileSystem(protocolId); if (fileSystem instanceof ArchiveFileSystem) { String path = VirtualFileManager.extractPath(url); ((ArchiveCopyingFileSystem)fileSystem).addNoCopyArchiveForPath(path); } } else if (root instanceof CompositeSdkRoot) { SdkRoot[] roots = ((CompositeSdkRoot)root).getProjectRoots(); for (SdkRoot root1 : roots) { addNoCopyArchiveForPaths(root1); } } }
@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; }
@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); }
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final Component rendererComponent = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (value != null) { String loc = value.toString().replace('\\', '/'); final int jarDelimIndex = loc.indexOf(ArchiveFileSystem.ARCHIVE_SEPARATOR); VirtualFile path = null; if (jarDelimIndex != -1) { final String protocol = VirtualFileManager.extractProtocol(loc); final VirtualFileSystem fileSystem = VirtualFileManager.getInstance().getFileSystem(protocol); if(fileSystem instanceof ArchiveFileSystem) { path = fileSystem.findFileByPath(loc); } } else { path = LocalFileSystem.getInstance().findFileByPath(loc); } setForeground(path != null ? isSelected ? UIUtil.getTableSelectionForeground() : Color.black : new Color(210, 0, 0)); } return rendererComponent; }
@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 JarFileSystem && file.getParent() == null) { return ((JarFileSystem)fs).getLocalVirtualFileFor(file); } return null; }
@Override @NotNull public VirtualFileSystem getFileSystem() { return new MockLocalFileSystem() { @Override public boolean equals(Object o) { return true; } }; }
public VcsVirtualFile(String path, byte[] content, String revision, VirtualFileSystem fileSystem) { this(path, null, fileSystem); myContent = content; setRevision(revision); }
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; }
public static PsiReference[] getReferences(@NotNull PsiElement element, String value, final String acceptedExtension) { final PsiDirectory directory = element.getContainingFile().getOriginalFile().getParent(); if (directory == null) return PsiReference.EMPTY_ARRAY; final boolean startsWithSlash = value.startsWith("/"); final VirtualFileSystem fs = directory.getVirtualFile().getFileSystem(); final FileReferenceSet fileReferenceSet = new FileReferenceSet(value, element, 1, null, fs.isCaseSensitive()) { @NotNull @Override public Collection<PsiFileSystemItem> getDefaultContexts() { if (startsWithSlash || !directory.isValid()) { return super.getDefaultContexts(); } return Collections.<PsiFileSystemItem>singletonList(directory); } @Override protected Condition<PsiFileSystemItem> getReferenceCompletionFilter() { return new Condition<PsiFileSystemItem>() { @Override public boolean value(PsiFileSystemItem item) { if (item instanceof PsiDirectory) return true; final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(item); return virtualFile != null && acceptedExtension.equals(virtualFile.getExtension()); } }; } }; if (startsWithSlash) { fileReferenceSet.addCustomization(FileReferenceSet.DEFAULT_PATH_EVALUATOR_OPTION, FileReferenceSet.ABSOLUTE_TOP_LEVEL); } return fileReferenceSet.getAllReferences(); }
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; } } } }
/** * Returns the IntelliJ virtual file system for the specified URI. * * @param uri The URI. * @return The file system; or <code>null</code> if not found. */ @Nullable private VirtualFileSystem getFileSystem(final URI uri) { switch (uri.getScheme()) { case "file": return StandardFileSystems.local(); case "zip": case "jar": return StandardFileSystems.jar(); default: return null; } }
@Nullable public static List<String> findUrlForVirtualFile(final Project project, final VirtualFile virtualFile, final String relPath) { final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); Module module = fileIndex.getModuleForFile(virtualFile); if (module == null) { final VirtualFileSystem fs = virtualFile.getFileSystem(); if (fs instanceof JarFileSystem) { final VirtualFile jar = ((JarFileSystem)fs).getVirtualFileForJar(virtualFile); if (jar != null) { module = fileIndex.getModuleForFile(jar); } } } if (module != null) { String[] javadocPaths = JavaModuleExternalPaths.getInstance(module).getJavadocUrls(); final List<String> httpRoots = PlatformDocumentationUtil.getHttpRoots(javadocPaths, relPath); // if found nothing and the file is from library classes, fall back to order entries if (httpRoots != null || !fileIndex.isInLibraryClasses(virtualFile)) { return httpRoots; } } final List<OrderEntry> orderEntries = fileIndex.getOrderEntriesForFile(virtualFile); for (OrderEntry orderEntry : orderEntries) { final String[] files = JavadocOrderRootType.getUrls(orderEntry); final List<String> httpRoot = PlatformDocumentationUtil.getHttpRoots(files, relPath); if (httpRoot != null) return httpRoot; } return null; }
@Nullable private static VirtualFile findPluginByRelativePath(@NotNull final VirtualFile hostFile, @NotNull @NonNls final String relPath, @NotNull final VirtualFileSystem fileSystem) { if (relPath.length() == 0) return hostFile; int index = relPath.indexOf('/'); if (index < 0) index = relPath.length(); String name = relPath.substring(0, index); VirtualFile child; if (name.equals(".")) { child = hostFile; } else if (name.equals("..")) { child = hostFile.getParent(); } else { child = fileSystem.findFileByPath(hostFile.getPath() + "/" + name); } if (child == null) return null; if (index < relPath.length()) { return findPluginByRelativePath(child, relPath.substring(index + 1), fileSystem); } else { return child; } }
@Nullable @Override public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull 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) { return createPanel(file); } } } return null; }
@NotNull public static VirtualFile getLocalFile(@NotNull VirtualFile libFile) { final VirtualFileSystem system = libFile.getFileSystem(); if (system instanceof JarFileSystem) { final VirtualFile local = JarFileSystem.getInstance().getVirtualFileForJar(libFile); if (local != null) { return local; } } return libFile; }
public static PsiReference[] getReferences(final PsiElement element, String value, final String acceptedExtension) { final PsiDirectory directory = element.getContainingFile().getOriginalFile().getParent(); if (directory == null) return PsiReference.EMPTY_ARRAY; final boolean startsWithSlash = value.startsWith("/"); final VirtualFileSystem fs = directory.getVirtualFile().getFileSystem(); final FileReferenceSet fileReferenceSet = new FileReferenceSet(value, element, 1, null, fs.isCaseSensitive()) { @NotNull @Override public Collection<PsiFileSystemItem> getDefaultContexts() { if (startsWithSlash || !directory.isValid()) { return super.getDefaultContexts(); } return Collections.<PsiFileSystemItem>singletonList(directory); } @Override protected Condition<PsiFileSystemItem> getReferenceCompletionFilter() { return new Condition<PsiFileSystemItem>() { @Override public boolean value(PsiFileSystemItem item) { if (item instanceof PsiDirectory) return true; final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(item); return virtualFile != null && acceptedExtension.equals(virtualFile.getExtension()); } }; } }; if (startsWithSlash) { fileReferenceSet.addCustomization(FileReferenceSet.DEFAULT_PATH_EVALUATOR_OPTION, FileReferenceSet.ABSOLUTE_TOP_LEVEL); } return fileReferenceSet.getAllReferences(); }
@Override public void actionPerformed(AnActionEvent e) { final Project project = e.getProject(); if (project == null) return; MyDialog dialog = new MyDialog(project); dialog.show(); if (dialog.isOK()) { Language language = dialog.getType(); project.putUserData(SCRATCH_LANGUAGE, language); Map<Language, Integer> previous = project.getUserData(SCRATCH_LANGUAGE_COUNTER_MAP); Map<Language, Integer> updated = updateMap(previous, language); project.putUserData(SCRATCH_LANGUAGE_COUNTER_MAP, updated); Integer integer = ObjectUtils.notNull(updated.get(language), 0); LanguageFileType associatedFileType = language.getAssociatedFileType(); String defaultExtension = associatedFileType != null ? associatedFileType.getDefaultExtension() : "unknown"; String index = integer == 1 ? "" : integer + "."; VirtualFile virtualFile = new LightVirtualFile("scratch." + index + defaultExtension, language, "") { @NotNull @Override public VirtualFileSystem getFileSystem() { return ScratchFileSystem.getScratchFileSystem(); } @Override public String getPath() { return "/" + project.getLocationHash() + super.getPath(); } }; ScratchFileSystem.getScratchFileSystem().addFile(virtualFile); OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile); FileEditorManager.getInstance(project).openTextEditor(descriptor, true); } }
@Override @Nonnull public VirtualFileSystem getFileSystem() { return new MockLocalFileSystem() { @Override public boolean equals(Object o) { return true; } }; }
@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; }
public VcsVirtualFile(@Nonnull String path, @Nonnull byte[] content, @Nullable String revision, @Nonnull VirtualFileSystem fileSystem) { this(path, null, fileSystem); myContent = content; setRevision(revision); }
public void actionPerformed(AnActionEvent e) { final Project project = getEventProject(e); final VirtualFile[] files = getFiles(e); if (project == null || files == null || files.length == 0) return; WriteAction.run(() -> { for (VirtualFile file : files) { final VirtualFileSystem fs = file.getFileSystem(); if (fs instanceof LocalFileSystem && file instanceof NewVirtualFile) { ((NewVirtualFile)file).markDirtyRecursively(); } } }); final Runnable postRefreshAction = new Runnable() { @Override public void run() { 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); }
@Nullable public static List<String> findUrlForVirtualFile(@NotNull Project project, @NotNull VirtualFile virtualFile, @NotNull String relPath) { final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); Module module = fileIndex.getModuleForFile(virtualFile); if(module == null) { final VirtualFileSystem fs = virtualFile.getFileSystem(); if(fs instanceof ArchiveFileSystem) { final VirtualFile jar = ((ArchiveFileSystem) fs).getLocalVirtualFileFor(virtualFile); if(jar != null) { module = fileIndex.getModuleForFile(jar); } } } for(OrderEntry orderEntry : fileIndex.getOrderEntriesForFile(virtualFile)) { final String[] files = orderEntry.getUrls(OrderRootType.DOCUMENTATION); final List<String> httpRoot = PlatformDocumentationUtil.getHttpRoots(files, relPath); if(httpRoot != null) { return httpRoot; } } return null; }
@NotNull @Override public VirtualFileSystem getFileSystem() { return DeltaHexFileSystem.getInstance(); }
@Nullable public static List<String> findUrlForVirtualFile(@NotNull Project project, @NotNull VirtualFile virtualFile, @NotNull String relPath) { final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); Module module = fileIndex.getModuleForFile(virtualFile); if (module == null) { final VirtualFileSystem fs = virtualFile.getFileSystem(); if (fs instanceof JarFileSystem) { final VirtualFile jar = ((JarFileSystem)fs).getVirtualFileForJar(virtualFile); if (jar != null) { module = fileIndex.getModuleForFile(jar); } } } if (module != null) { String[] javadocPaths = JavaModuleExternalPaths.getInstance(module).getJavadocUrls(); final List<String> httpRoots = PlatformDocumentationUtil.getHttpRoots(javadocPaths, relPath); // if found nothing and the file is from library classes, fall back to order entries if (httpRoots != null || !fileIndex.isInLibraryClasses(virtualFile)) { return httpRoots; } } for (OrderEntry orderEntry : fileIndex.getOrderEntriesForFile(virtualFile)) { for (VirtualFile root : orderEntry.getFiles(JavadocOrderRootType.getInstance())) { if (root.getFileSystem() == JarFileSystem.getInstance()) { VirtualFile file = root.findFileByRelativePath(relPath); List<Url> urls = file == null ? null : BuiltInWebBrowserUrlProvider.getUrls(file, project, null); if (!ContainerUtil.isEmpty(urls)) { List<String> result = new SmartList<String>(); for (Url url : urls) { result.add(url.toExternalForm()); } return result; } } } List<String> httpRoot = PlatformDocumentationUtil.getHttpRoots(JavadocOrderRootType.getUrls(orderEntry), relPath); if (httpRoot != null) { return httpRoot; } } return null; }
@NotNull private static VirtualFileSystem getLocalFileSystem() { // Use VFM directly because of mocks in tests. return VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL); }