jetbrains-ultimate/tst-212/com/goide/vgo/VgoTestUtil.java [39:123]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class VgoTestUtil {
    private static final String GOPATH = getGoTestDataPath("vgo/src/test/testData/mockGoPath").getAbsolutePath();
    private static final Map<String, VgoDependency> DEPENDENCIES =
        ContainerUtil.newHashMap(dependencyPair("vgoDep", "v1.5.2", null, null),
                                 dependencyPair("vgoTransitiveDep", "v1.0.0", null, null),
                                 dependencyPair("customDir", "v0.0.0", "customDirDep@v1.0.0", null),
                                 dependencyPair("originalDep", "v1.0.0", null, dependency("replacedDep", "v1.0.0", null, null)));
    public static final String DEFAULT_IMPORT_PATH = "jetbrains.com/hello";

    @NotNull
    private static Pair<String, VgoDependencyImpl> dependencyPair(@NotNull String importPath,
                                                                  @NotNull String version,
                                                                  @Nullable String dir,
                                                                  @Nullable VgoDependencyImpl replace) {
        VgoDependencyImpl dependency = dependency(importPath, version, dir, replace);
        return Pair.create(dependency.getDirPath(), dependency);
    }

    @NotNull
    private static VgoDependencyImpl dependency(@NotNull String importPath,
                                                @NotNull String version,
                                                @Nullable String dir,
                                                @Nullable VgoDependencyImpl replace) {
        String dirName = dir != null ? dir : String.format("%s@%s", importPath, version);
        String dirPath = FileUtil.join(GOPATH, "pkg", GoConstants.VGO_DIR_NAME, dirName);
        return new VgoDependencyImpl(importPath, version, null, PathUtil.toSystemIndependentName(FileUtil.toCanonicalPath(dirPath)), replace, false);
    }

    public static PsiFile setupVgoIntegration(@NotNull CodeInsightTestFixture fixture) {
        return setupVgoIntegration(null, DEFAULT_IMPORT_PATH, fixture, DEPENDENCIES);
    }

    public static PsiFile setupVgoIntegration(@Nullable String modulePath,
                                              @NotNull String importPath,
                                              @NotNull CodeInsightTestFixture fixture,
                                              @NotNull Map<String, VgoDependency> dependencies) {
        setupGopath(fixture, null);
        VgoModule module = createVgoModule(fixture, modulePath, importPath, dependencies);
        setupVgoIntegration(fixture, Collections.singletonList(module));
        return getGoModPsiFile(fixture, module);
    }

    @NotNull
    public static VirtualFile setupGopath(@NotNull CodeInsightTestFixture fixture, @Nullable String customGopath) {
        if (customGopath == null) {
            GoModuleLibrariesService.getInstance(fixture.getModule()).setLibraryRootUrls(VfsUtilCore.pathToUrl(GOPATH));
            return VfsTestUtil.findFileByCaseSensitivePath(GOPATH);
        }
        VirtualFile customGopathFile = VfsUtil.findFile(Paths.get(fixture.getTestDataPath(), customGopath), true);
        if (customGopathFile != null) {
            // Sometimes changes in custom gopath directory are not detected by tests, we explicitly refresh to overcome this.
            customGopathFile.refresh(false, true);
            GoModuleLibrariesService.getInstance(fixture.getModule()).setLibraryRootUrls(customGopathFile.getUrl());
            return customGopathFile;
        }
        throw new IllegalArgumentException("Cannot find custom gopath: " + customGopath);
    }

    @NotNull
    // made public
    public static VgoModule createVgoModule(@NotNull CodeInsightTestFixture fixture,
                                            @Nullable String modulePath,
                                            @NotNull String importPath,
                                            @NotNull Map<String, VgoDependency> dependencies) {
        String goModPath = modulePath != null ? FileUtil.join(modulePath, VgoUtil.GO_MOD) : VgoUtil.GO_MOD;
        PsiFile file = fixture.addFileToProject(goModPath, "module \"" + importPath + "\"");
        return new VgoModule(file.getVirtualFile().getParent(), importPath, dependencies);
    }

    public static void setupVgoIntegration(@NotNull CodeInsightTestFixture fixture, @NotNull List<VgoModule> modules) {
        VgoExcludeRootsPolicy.setPointersDisposable(fixture.getTestRootDisposable());
        // GoVendorExcludePolicy.setPointersDisposable(fixture.getTestRootDisposable());
        TestModeFlags.set(VgoIntegrationManager.DISABLE_TRACKERS, true, fixture.getTestRootDisposable());
        VgoProjectSettings.getInstance(fixture.getProject()).setIntegrationEnabled(true);
        setVgoModules(fixture, modules);
        Disposer.register(fixture.getTestRootDisposable(), () -> {
            VgoProjectSettings.getInstance(fixture.getProject()).setIntegrationEnabled(false);
            VgoModulesRegistry.getInstance(fixture.getProject()).updateAllModules(fixture.getModule(), Collections.emptySet());
            PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue();
        });
        PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue();
    }

    public static void setVgoModules(@NotNull CodeInsightTestFixture fixture, @NotNull List<VgoModule> modules) {
        for (VgoModule module : modules) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



jetbrains-ultimate/tst-213+/com/goide/vgo/VgoTestUtil.java [40:124]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class VgoTestUtil {
    private static final String GOPATH = getGoTestDataPath("vgo/src/test/testData/mockGoPath").getAbsolutePath();
    private static final Map<String, VgoDependency> DEPENDENCIES =
        ContainerUtil.newHashMap(dependencyPair("vgoDep", "v1.5.2", null, null),
                                 dependencyPair("vgoTransitiveDep", "v1.0.0", null, null),
                                 dependencyPair("customDir", "v0.0.0", "customDirDep@v1.0.0", null),
                                 dependencyPair("originalDep", "v1.0.0", null, dependency("replacedDep", "v1.0.0", null, null)));
    public static final String DEFAULT_IMPORT_PATH = "jetbrains.com/hello";

    @NotNull
    private static Pair<String, VgoDependencyImpl> dependencyPair(@NotNull String importPath,
                                                                  @NotNull String version,
                                                                  @Nullable String dir,
                                                                  @Nullable VgoDependencyImpl replace) {
        VgoDependencyImpl dependency = dependency(importPath, version, dir, replace);
        return Pair.create(dependency.getDirPath(), dependency);
    }

    @NotNull
    private static VgoDependencyImpl dependency(@NotNull String importPath,
                                                @NotNull String version,
                                                @Nullable String dir,
                                                @Nullable VgoDependencyImpl replace) {
        String dirName = dir != null ? dir : String.format("%s@%s", importPath, version);
        String dirPath = FileUtil.join(GOPATH, "pkg", GoConstants.VGO_DIR_NAME, dirName);
        return new VgoDependencyImpl(importPath, version, null, PathUtil.toSystemIndependentName(FileUtil.toCanonicalPath(dirPath)), replace, false);
    }

    public static PsiFile setupVgoIntegration(@NotNull CodeInsightTestFixture fixture) {
        return setupVgoIntegration(null, DEFAULT_IMPORT_PATH, fixture, DEPENDENCIES);
    }

    public static PsiFile setupVgoIntegration(@Nullable String modulePath,
                                              @NotNull String importPath,
                                              @NotNull CodeInsightTestFixture fixture,
                                              @NotNull Map<String, VgoDependency> dependencies) {
        setupGopath(fixture, null);
        VgoModule module = createVgoModule(fixture, modulePath, importPath, dependencies);
        setupVgoIntegration(fixture, Collections.singletonList(module));
        return getGoModPsiFile(fixture, module);
    }

    @NotNull
    public static VirtualFile setupGopath(@NotNull CodeInsightTestFixture fixture, @Nullable String customGopath) {
        if (customGopath == null) {
            GoModuleLibrariesService.getInstance(fixture.getModule()).setLibraryRootUrls(VfsUtilCore.pathToUrl(GOPATH));
            return VfsTestUtil.findFileByCaseSensitivePath(GOPATH);
        }
        VirtualFile customGopathFile = VfsUtil.findFile(Paths.get(fixture.getTestDataPath(), customGopath), true);
        if (customGopathFile != null) {
            // Sometimes changes in custom gopath directory are not detected by tests, we explicitly refresh to overcome this.
            customGopathFile.refresh(false, true);
            GoModuleLibrariesService.getInstance(fixture.getModule()).setLibraryRootUrls(customGopathFile.getUrl());
            return customGopathFile;
        }
        throw new IllegalArgumentException("Cannot find custom gopath: " + customGopath);
    }

    @NotNull
    // made public
    public static VgoModule createVgoModule(@NotNull CodeInsightTestFixture fixture,
                                            @Nullable String modulePath,
                                            @NotNull String importPath,
                                            @NotNull Map<String, VgoDependency> dependencies) {
        String goModPath = modulePath != null ? FileUtil.join(modulePath, VgoUtil.GO_MOD) : VgoUtil.GO_MOD;
        PsiFile file = fixture.addFileToProject(goModPath, "module \"" + importPath + "\"");
        return new VgoModule(file.getVirtualFile().getParent(), importPath, dependencies);
    }

    public static void setupVgoIntegration(@NotNull CodeInsightTestFixture fixture, @NotNull List<VgoModule> modules) {
        VgoExcludeRootsPolicy.setPointersDisposable(fixture.getTestRootDisposable());
        // GoVendorExcludePolicy.setPointersDisposable(fixture.getTestRootDisposable());
        TestModeFlags.set(VgoIntegrationManager.DISABLE_TRACKERS, true, fixture.getTestRootDisposable());
        VgoProjectSettings.getInstance(fixture.getProject()).setIntegrationEnabled(true);
        setVgoModules(fixture, modules);
        Disposer.register(fixture.getTestRootDisposable(), () -> {
            VgoProjectSettings.getInstance(fixture.getProject()).setIntegrationEnabled(false);
            VgoModulesRegistry.getInstance(fixture.getProject()).updateAllModules(fixture.getModule(), Collections.emptySet());
            PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue();
        });
        PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue();
    }

    public static void setVgoModules(@NotNull CodeInsightTestFixture fixture, @NotNull List<VgoModule> modules) {
        for (VgoModule module : modules) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



