Java Code Examples for com.intellij.openapi.vfs.VirtualFile#getUrl()

The following examples show how to use com.intellij.openapi.vfs.VirtualFile#getUrl() . 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: Unity3dProjectChangeListener.java    From consulo-unity3d with Apache License 2.0 6 votes vote down vote up
private void handleChange(@Nonnull VirtualFile virtualFile)
{
	if(!myActive.get())
	{
		return;
	}

	if(!mySourceFileTypes.contains(virtualFile.getFileType()))
	{
		return;
	}

	String url = virtualFile.getUrl();
	if(url.startsWith(myAssetsDirPointer.getUrl()))
	{
		myDataBlock.myFiles.add(virtualFile);
	}
}
 
Example 2
Source File: XSDToRAMLAction.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent anActionEvent)
{
    final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(anActionEvent.getDataContext());
    final Project project = anActionEvent.getProject();

    Xsd2Raml xsd2Raml = new Xsd2Raml(file.getUrl());
    String raml = xsd2Raml.getRaml();

    PsiFile psiFile = PsiFileFactory.getInstance(anActionEvent.getProject()).createFileFromText(RamlLanguage.INSTANCE, raml);

    new WriteCommandAction.Simple(project, psiFile) {
        @Override
        protected void run() throws Throwable {
            psiFile.setName(file.getNameWithoutExtension() + "." + RamlFileType.INSTANCE.getDefaultExtension());

            PsiDirectory directory = CommonDataKeys.PSI_FILE.getData(anActionEvent.getDataContext()).getContainingDirectory();
            directory.add(psiFile);
        }
    }.execute();

}
 
Example 3
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 4
Source File: VcsRootIterator.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void init(final VcsRoot[] allRoots) {
  final String ourPath = myRoot.getUrl();

  for (VcsRoot root : allRoots) {
    final AbstractVcs vcs = root.getVcs();
    if (vcs == null || Comparing.equal(vcs.getName(), myVcsName)) continue;
    final VirtualFile path = root.getPath();
    if (path != null) {
      final String url = path.getUrl();
      if (url.startsWith(ourPath)) {
        myExcludedByOthers.add(url);
      }
    }
  }

  Collections.sort(myExcludedByOthers, StringLenComparator.getDescendingInstance());
}
 
Example 5
Source File: PlatformDocumentationUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public static List<String> getHttpRoots(final String[] roots, String relPath) {
  final ArrayList<String> result = new ArrayList<String>();
  for (String root : roots) {
    final VirtualFile virtualFile = VirtualFileManager.getInstance().findFileByUrl(root);
    if (virtualFile != null) {
      if (virtualFile.getFileSystem() instanceof HttpFileSystem) {
        String url = virtualFile.getUrl();
        if (!url.endsWith("/")) url += "/";
        result.add(url + relPath);
      }
      else {
        VirtualFile file = virtualFile.findFileByRelativePath(relPath);
        if (file != null) result.add(file.getUrl());
      }
    }
  }

  return result.isEmpty() ? null : result;
}
 
Example 6
Source File: TranslationCompilerProjectMonitor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
public Map<String, Couple<String>> buildOutputRootsLayout() {
  Map<String, Couple<String>> map = new LinkedHashMap<>();

  for (Module module : ModuleManager.getInstance(myProject).getModules()) {
    ModuleCompilerPathsManager moduleCompilerPathsManager = ModuleCompilerPathsManager.getInstance(module);

    final VirtualFile output = moduleCompilerPathsManager.getCompilerOutput(ProductionContentFolderTypeProvider.getInstance());
    final String outputUrl = output == null ? null : output.getUrl();
    final VirtualFile testsOutput = moduleCompilerPathsManager.getCompilerOutput(TestContentFolderTypeProvider.getInstance());
    final String testoutUrl = testsOutput == null ? null : testsOutput.getUrl();
    map.put(module.getName(), Couple.of(outputUrl, testoutUrl));
  }

  return map;
}
 
Example 7
Source File: NewLibraryEditor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public VirtualFile[] getFiles(@Nonnull OrderRootType rootType) {
  List<VirtualFile> result = new ArrayList<>();
  for (LightFilePointer pointer : myRoots.get(rootType)) {
    final VirtualFile file = pointer.getFile();
    if (file == null) {
      continue;
    }

    if (file.isDirectory()) {
      final String url = file.getUrl();
      if (isJarDirectory(url, rootType)) {
        boolean recursive = myJarDirectoryRecursiveUrls.get(rootType).contains(url);
        collectJarFiles(file, result, recursive);
        continue;
      }
    }
    result.add(file);
  }
  return VfsUtilCore.toVirtualFileArray(result);
}
 
Example 8
Source File: VcsRootIterator.java    From consulo with Apache License 2.0 5 votes vote down vote up
public boolean accept(final VirtualFile vf) {
  final String url = vf.getUrl();
  for (String excludedByOtherVcs : myExcludedByOthers) {
    // use the fact that they are sorted
    if (url.length() > excludedByOtherVcs.length()) return true;
    if (url.startsWith(excludedByOtherVcs)) return false;
  }
  return true;
}
 
Example 9
Source File: VcsRootIterator.java    From consulo with Apache License 2.0 5 votes vote down vote up
public boolean acceptFolderUnderVcs(final VirtualFile vcsRoot, final VirtualFile file) {
  final String vcsUrl = vcsRoot.getUrl();
  final MyRootFilter rootFilter = myOtherVcsFolders.get(vcsUrl);
  if ((rootFilter != null) && (! rootFilter.accept(file))) {
    return false;
  }
  final Boolean excluded = isExcluded(myExcludedFileIndex, file);
  if (excluded) return false;
  return true;
}
 
Example 10
Source File: RefElementImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public String getURL() {
  final PsiElement element = getPsiElement();
  if (element == null || !element.isPhysical()) return null;
  final PsiFile containingFile = element.getContainingFile();
  if (containingFile == null) return null;
  final VirtualFile virtualFile = containingFile.getVirtualFile();
  if (virtualFile == null) return null;
  return virtualFile.getUrl() + "#" + element.getTextOffset();
}
 
Example 11
Source File: PsiFileUrl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public AbstractUrl createUrlByElement(Object element) {
  if (element instanceof PsiFile) {
    VirtualFile file = ((PsiFile)element).getVirtualFile();
    if (file != null){
      return new PsiFileUrl(file.getUrl());
    }
  }
  return null;
}
 
Example 12
Source File: ArtifactUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static String getDefaultArtifactOutputPath(@Nonnull String artifactName, final @Nonnull Project project) {
  final CompilerConfiguration extension = CompilerConfiguration.getInstance(project);
  String outputUrl = extension.getCompilerOutputUrl();
  if (outputUrl == null || outputUrl.length() == 0) {
    final VirtualFile baseDir = project.getBaseDir();
    if (baseDir == null) return null;
    outputUrl = baseDir.getUrl() + "/out";
  }
  return VfsUtil.urlToPath(outputUrl) + "/artifacts/" + FileUtil.sanitizeFileName(artifactName);
}
 
Example 13
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 14
Source File: HaxeLibrary.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
private HaxeLibrary(@NotNull String name, @NotNull VirtualFile libraryRoot, @NotNull HaxelibLibraryCache owner) {
  myCache = owner;
  myLibraryRoot = libraryRoot.getUrl();

  myMetadata = HaxelibMetadata.load(libraryRoot);
  HaxeLibraryInfo pathInfo = HaxelibUtil.deriveLibraryInfoFromPath(owner.getSdk(), libraryRoot.getPath());

  String mdname = myMetadata.getName();
  if (null != mdname && !mdname.isEmpty()) {
    myName = mdname;
  } else if (!name.isEmpty()) {
    myName = name;
  } else {
    myName = pathInfo == null ? "" : pathInfo.getName();
  }

  HaxelibSemVer semVer = HaxelibSemVer.create(myMetadata.getVersion());
  if (HaxelibSemVer.ZERO_VERSION == semVer && pathInfo != null) {
    semVer = pathInfo.getVersion();
  }
  mySemVer = semVer;

  String cp = myMetadata.getClasspath();
  if ((null == cp || cp.isEmpty()) && pathInfo != null) {
      cp = pathInfo.getClasspath();
  }
  if (null != cp && !cp.isEmpty()) {
    myRelativeClasspath = cp;
  } else {
    myRelativeClasspath = CURRENT_DIR;
  }
}
 
Example 15
Source File: OneProjectItemCompileScope.java    From consulo with Apache License 2.0 4 votes vote down vote up
public OneProjectItemCompileScope(Project project, VirtualFile file) {
  myProject = project;
  myFile = file;
  final String url = file.getUrl();
  myUrl = file.isDirectory()? url + "/" : url;
}
 
Example 16
Source File: LightFilePointer.java    From consulo with Apache License 2.0 4 votes vote down vote up
public LightFilePointer(@Nonnull VirtualFile file) {
  myUrl = file.getUrl();
  myFile = file;
}
 
Example 17
Source File: RefFileImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public String getExternalName() {
  final PsiFile psiFile = getPsiElement();
  final VirtualFile virtualFile = psiFile != null ? psiFile.getVirtualFile() : null;
  return virtualFile != null ? virtualFile.getUrl() : getName();
}
 
Example 18
Source File: ContentEntryImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public ContentEntryImpl(@Nonnull VirtualFile file, @Nonnull ModuleRootLayerImpl m) {
  this(file.getUrl(), m);
}
 
Example 19
Source File: DirectoryUrl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static DirectoryUrl create(PsiDirectory directory) {
  Project project = directory.getProject();
  final VirtualFile virtualFile = directory.getVirtualFile();
  final Module module = ModuleUtil.findModuleForFile(virtualFile, project);
  return new DirectoryUrl(virtualFile.getUrl(), module != null ? module.getName() : null);
}
 
Example 20
Source File: ExcludeEntryDescription.java    From consulo with Apache License 2.0 4 votes vote down vote up
public ExcludeEntryDescription(VirtualFile virtualFile, boolean includeSubdirectories, boolean isFile, Disposable parent) {
  this(virtualFile.getUrl(), includeSubdirectories, isFile, parent);
}