Java Code Examples for com.intellij.openapi.vfs.VirtualFileManager#extractPath()

The following examples show how to use com.intellij.openapi.vfs.VirtualFileManager#extractPath() . 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: ExternalSystemImportingTestCase.java    From intellij-quarkus with Eclipse Public License 2.0 6 votes vote down vote up
protected static List<SourceFolder> doAssertContentFolders(@Nullable String rootUrl,
                                                         ContentEntry[] contentRoots,
                                                         @NotNull JpsModuleSourceRootType<?> rootType,
                                                         String... expected) {
  List<SourceFolder> result = new ArrayList<>();
  List<String> actual = new ArrayList<>();
  for (ContentEntry contentRoot : contentRoots) {
    for (SourceFolder f : contentRoot.getSourceFolders(rootType)) {
      rootUrl = VirtualFileManager.extractPath(rootUrl == null ? contentRoot.getUrl() : rootUrl);
      String folderUrl = VirtualFileManager.extractPath(f.getUrl());
      if (folderUrl.startsWith(rootUrl)) {
        int length = rootUrl.length() + 1;
        folderUrl = folderUrl.substring(Math.min(length, folderUrl.length()));
      }

      actual.add(folderUrl);
      result.add(f);
    }
  }

  assertOrderedElementsAreEqual(actual, Arrays.asList(expected));
  return result;
}
 
Example 2
Source File: CompilerPathsImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@javax.annotation.Nullable
public static String getModuleOutputPath(final Module module, final ContentFolderTypeProvider contentFolderType) {
  final String outPathUrl;
  final Application application = ApplicationManager.getApplication();
  final ModuleCompilerPathsManager pathsManager = ModuleCompilerPathsManager.getInstance(module);

  if (application.isDispatchThread()) {
    outPathUrl = pathsManager.getCompilerOutputUrl(contentFolderType);
  }
  else {
    outPathUrl = application.runReadAction(new Computable<String>() {
      @Override
      public String compute() {
        return pathsManager.getCompilerOutputUrl(contentFolderType);
      }
    });
  }

  return outPathUrl != null ? VirtualFileManager.extractPath(outPathUrl) : null;
}
 
Example 3
Source File: CompilerPathsImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * The same as {@link #getModuleOutputDirectory} but returns String.
 * The method still returns a non-null value if the output path is specified in Settings but does not exist on disk.
 */
@javax.annotation.Nullable
@Deprecated
public static String getModuleOutputPath(final Module module, final boolean forTestClasses) {
  final String outPathUrl;
  final Application application = ApplicationManager.getApplication();
  final ModuleCompilerPathsManager pathsManager = ModuleCompilerPathsManager.getInstance(module);

  if (application.isDispatchThread()) {
    outPathUrl = pathsManager.getCompilerOutputUrl(
      forTestClasses ? TestContentFolderTypeProvider.getInstance() : ProductionContentFolderTypeProvider.getInstance());
  }
  else {
    outPathUrl = application.runReadAction(new Computable<String>() {
      @Override
      public String compute() {
        return pathsManager.getCompilerOutputUrl(
          forTestClasses ? TestContentFolderTypeProvider.getInstance() : ProductionContentFolderTypeProvider.getInstance());
      }
    });
  }

  return outPathUrl != null ? VirtualFileManager.extractPath(outPathUrl) : null;
}
 
Example 4
Source File: SMTestProxy.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected Location getLocation(@Nonnull Project project, @Nonnull GlobalSearchScope searchScope, String locationUrl) {
  if (locationUrl != null && myLocator != null) {
    String protocolId = VirtualFileManager.extractProtocol(locationUrl);
    if (protocolId != null) {
      String path = VirtualFileManager.extractPath(locationUrl);
      if (!DumbService.isDumb(project) || DumbService.isDumbAware(myLocator)) {
        return DumbService.getInstance(project).computeWithAlternativeResolveEnabled(() -> {
          List<Location> locations = myLocator.getLocation(protocolId, path, myMetainfo, project, searchScope);
          return !locations.isEmpty() ? locations.get(0) : null;
        });
      }
    }
  }

  return null;
}
 
Example 5
Source File: BlazeGoTestEventsHandlerTest.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
private Location<?> getLocation(String url) {
  String protocol = VirtualFileManager.extractProtocol(url);
  if (protocol == null) {
    return null;
  }
  String path = VirtualFileManager.extractPath(url);
  assertThat(handler.getTestLocator()).isNotNull();
  @SuppressWarnings("rawtypes")
  List<Location> locations =
      handler
          .getTestLocator()
          .getLocation(protocol, path, getProject(), GlobalSearchScope.allScope(getProject()));
  assertThat(locations).hasSize(1);
  return locations.get(0);
}
 
Example 6
Source File: BlazeWebJavascriptTestEventsHandlerTest.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
private Location<?> getLocation(String url) {
  String protocol = VirtualFileManager.extractProtocol(url);
  if (protocol == null) {
    return null;
  }
  String path = VirtualFileManager.extractPath(url);
  assertThat(handler.getTestLocator()).isNotNull();
  @SuppressWarnings("rawtypes")
  List<Location> locations =
      handler
          .getTestLocator()
          .getLocation(protocol, path, getProject(), GlobalSearchScope.allScope(getProject()));
  assertThat(locations).hasSize(1);
  return locations.get(0);
}
 
Example 7
Source File: BlazeJavascriptWebTestEventsHandlerTest.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
private Location<?> getLocation(String url) {
  String protocol = VirtualFileManager.extractProtocol(url);
  if (protocol == null) {
    return null;
  }
  String path = VirtualFileManager.extractPath(url);
  assertThat(handler.getTestLocator()).isNotNull();
  @SuppressWarnings("rawtypes")
  List<Location> locations =
      handler
          .getTestLocator()
          .getLocation(protocol, path, getProject(), GlobalSearchScope.allScope(getProject()));
  assertThat(locations).hasSize(1);
  return locations.get(0);
}
 
Example 8
Source File: BlazeGoWebTestEventsHandlerTest.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
private Location<?> getLocation(String url) {
  String protocol = VirtualFileManager.extractProtocol(url);
  if (protocol == null) {
    return null;
  }
  String path = VirtualFileManager.extractPath(url);
  assertThat(handler.getTestLocator()).isNotNull();
  @SuppressWarnings("rawtypes")
  List<Location> locations =
      handler
          .getTestLocator()
          .getLocation(protocol, path, getProject(), GlobalSearchScope.allScope(getProject()));
  assertThat(locations).hasSize(1);
  return locations.get(0);
}
 
Example 9
Source File: BlazeWebGoTestEventsHandlerTest.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
private Location<?> getLocation(String url) {
  String protocol = VirtualFileManager.extractProtocol(url);
  if (protocol == null) {
    return null;
  }
  String path = VirtualFileManager.extractPath(url);
  assertThat(handler.getTestLocator()).isNotNull();
  @SuppressWarnings("rawtypes")
  List<Location> locations =
      handler
          .getTestLocator()
          .getLocation(protocol, path, getProject(), GlobalSearchScope.allScope(getProject()));
  assertThat(locations).hasSize(1);
  return locations.get(0);
}
 
Example 10
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 11
Source File: LightFilePointer.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static String toPresentableUrl(String url) {
  String path = VirtualFileManager.extractPath(url);
  if (path.endsWith(ArchiveFileSystem.ARCHIVE_SEPARATOR)) {
    path = path.substring(0, path.length() - ArchiveFileSystem.ARCHIVE_SEPARATOR.length());
  }
  return path.replace('/', File.separatorChar);
}
 
Example 12
Source File: LibraryEditingUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void copyLibrary(LibraryEx from, Map<String, String> rootMapping, LibraryEx.ModifiableModelEx target) {
  target.setProperties(from.getProperties());
  for (OrderRootType type : OrderRootType.getAllTypes()) {
    final String[] urls = from.getUrls(type);
    for (String url : urls) {
      final String protocol = VirtualFileManager.extractProtocol(url);
      if (protocol == null) continue;
      final String fullPath = VirtualFileManager.extractPath(url);
      final int sep = fullPath.indexOf(ArchiveFileSystem.ARCHIVE_SEPARATOR);
      String localPath;
      String pathInJar;
      if (sep != -1) {
        localPath = fullPath.substring(0, sep);
        pathInJar = fullPath.substring(sep);
      }
      else {
        localPath = fullPath;
        pathInJar = "";
      }
      final String targetPath = rootMapping.get(localPath);
      String targetUrl = targetPath != null ? VirtualFileManager.constructUrl(protocol, targetPath + pathInJar) : url;

      if (from.isJarDirectory(url, type)) {
        target.addJarDirectory(targetUrl, false, type);
      }
      else {
        target.addRoot(targetUrl, type);
      }
    }
  }
}
 
Example 13
Source File: BlazePythonTestEventsHandlerTest.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
private Location<?> getLocation(String url) {
  String protocol = VirtualFileManager.extractProtocol(url);
  String path = VirtualFileManager.extractPath(url);
  if (protocol == null) {
    return null;
  }
  return Iterables.getFirst(
      handler
          .getTestLocator()
          .getLocation(protocol, path, getProject(), GlobalSearchScope.allScope(getProject())),
      null);
}
 
Example 14
Source File: BlazeJavaTestEventsHandlerTest.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
private Location<?> getLocation(String url) {
  String protocol = VirtualFileManager.extractProtocol(url);
  String path = VirtualFileManager.extractPath(url);
  if (protocol == null) {
    return null;
  }
  return Iterables.getFirst(
      handler
          .getTestLocator()
          .getLocation(protocol, path, getProject(), GlobalSearchScope.allScope(getProject())),
      null);
}
 
Example 15
Source File: BlazeWebJavaTestEventsHandlerTest.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
private Location<?> getLocation(String url) {
  String protocol = VirtualFileManager.extractProtocol(url);
  String path = VirtualFileManager.extractPath(url);
  if (protocol == null) {
    return null;
  }
  SMTestLocator locator = handler.getTestLocator();
  assertThat(locator).isNotNull();
  return Iterables.getFirst(
      locator.getLocation(protocol, path, getProject(), GlobalSearchScope.allScope(getProject())),
      null);
}
 
Example 16
Source File: BlazeJavaWebTestEventsHandlerTest.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
private Location<?> getLocation(String url) {
  String protocol = VirtualFileManager.extractProtocol(url);
  String path = VirtualFileManager.extractPath(url);
  if (protocol == null) {
    return null;
  }
  SMTestLocator locator = handler.getTestLocator();
  assertThat(locator).isNotNull();
  return Iterables.getFirst(
      locator.getLocation(protocol, path, getProject(), GlobalSearchScope.allScope(getProject())),
      null);
}
 
Example 17
Source File: JavaSourceFolderProvider.java    From intellij with Apache License 2.0 5 votes vote down vote up
private static String derivePackagePrefix(File file, SourceFolder parentFolder) {
  String parentPackagePrefix = parentFolder.getPackagePrefix();
  String parentPath = VirtualFileManager.extractPath(parentFolder.getUrl());
  String relativePath =
      FileUtil.toCanonicalPath(
          FileUtil.getRelativePath(parentPath, file.getPath(), File.separatorChar));
  if (Strings.isNullOrEmpty(relativePath)) {
    return parentPackagePrefix;
  }
  // FileUtil.toCanonicalPath already replaces File.separatorChar with '/'
  relativePath = relativePath.replace('/', '.');
  return Strings.isNullOrEmpty(parentPackagePrefix)
      ? relativePath
      : parentPackagePrefix + "." + relativePath;
}
 
Example 18
Source File: ItemElement.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static String getPresentablePath(final String url) {
  String presentablePath = VirtualFileManager.extractPath(url);
  if (isArchiveFileRoot(url)) {
    presentablePath = presentablePath.substring(0, presentablePath.length() - ArchiveFileSystem.ARCHIVE_SEPARATOR.length());
  }
  return presentablePath;
}
 
Example 19
Source File: UrlUtil.java    From intellij with Apache License 2.0 4 votes vote down vote up
public static File urlToFile(String url) {
  return new File(VirtualFileManager.extractPath(url));
}
 
Example 20
Source File: ModuleImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public String getModuleDirPath() {
  return myDirVirtualFilePointer == null ? null : VirtualFileManager.extractPath(myDirVirtualFilePointer.getUrl());
}