Search in sources :

Example 21 with DartSdk

use of com.jetbrains.lang.dart.sdk.DartSdk in project intellij-plugins by JetBrains.

the class DartSdkConfigurationTest method testSdkRootsFromLibrariesFile.

public void testSdkRootsFromLibrariesFile() throws Exception {
    final DartSdk sdk = DartSdk.getDartSdk(getProject());
    assertNotNull(sdk);
    final String[] actualRoots = ArrayUtil.toStringArray(DartSdkLibUtil.getRootUrlsFromLibrariesFile(getProject(), sdk.getHomePath()));
    checkSdkRoots(sdk.getHomePath(), actualRoots);
}
Also used : DartSdk(com.jetbrains.lang.dart.sdk.DartSdk)

Example 22 with DartSdk

use of com.jetbrains.lang.dart.sdk.DartSdk in project intellij-plugins by JetBrains.

the class DartSdkConfigurationTest method testSdkRoots.

public void testSdkRoots() throws Exception {
    final DartSdk sdk = DartSdk.getDartSdk(getProject());
    assertNotNull(sdk);
    final String[] actualRoots = ProjectLibraryTable.getInstance(getProject()).getLibraries()[0].getRootProvider().getUrls(OrderRootType.CLASSES);
    checkSdkRoots(sdk.getHomePath(), actualRoots);
}
Also used : DartSdk(com.jetbrains.lang.dart.sdk.DartSdk)

Example 23 with DartSdk

use of com.jetbrains.lang.dart.sdk.DartSdk in project intellij-plugins by JetBrains.

the class DartAnalysisServerService method doConfigureImportedLibraries.

private static void doConfigureImportedLibraries(@NotNull final Project project, @NotNull final Collection<String> filePaths) {
    final DartSdk sdk = DartSdk.getDartSdk(project);
    if (sdk == null)
        return;
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    final SortedSet<String> folderPaths = new TreeSet<>();
    final Collection<String> rootsToAddToLib = new THashSet<>();
    for (final String path : filePaths) {
        if (path != null) {
            folderPaths.add(PathUtil.getParentPath(FileUtil.toSystemIndependentName(path)));
        }
    }
    outer: for (final String path : folderPaths) {
        final VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(path);
        if (!path.startsWith(sdk.getHomePath() + "/") && (vFile == null || !fileIndex.isInContent(vFile))) {
            for (String configuredPath : rootsToAddToLib) {
                if (path.startsWith(configuredPath + "/")) {
                    // folderPaths is sorted so subfolders go after parent folder
                    continue outer;
                }
            }
            rootsToAddToLib.add(path);
        }
    }
    final Processor<? super PsiFileSystemItem> falseProcessor = (Processor<PsiFileSystemItem>) item -> false;
    final Condition<Module> moduleFilter = module -> DartSdkLibUtil.isDartSdkEnabled(module) && !FilenameIndex.processFilesByName(PubspecYamlUtil.PUBSPEC_YAML, false, falseProcessor, module.getModuleContentScope(), project, null);
    final DartFileListener.DartLibInfo libInfo = new DartFileListener.DartLibInfo(true);
    libInfo.addRoots(rootsToAddToLib);
    final Library library = DartFileListener.updatePackagesLibraryRoots(project, libInfo);
    DartFileListener.updateDependenciesOnDartPackagesLibrary(project, moduleFilter, library);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartFileType(com.jetbrains.lang.dart.DartFileType) UIUtil(com.intellij.util.ui.UIUtil) HtmlUtil(com.intellij.xml.util.HtmlUtil) DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) Logging(com.google.dart.server.utilities.logging.Logging) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModalityState(com.intellij.openapi.application.ModalityState) Document(com.intellij.openapi.editor.Document) THashSet(gnu.trove.THashSet) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) THashMap(gnu.trove.THashMap) FileEditorManagerEvent(com.intellij.openapi.fileEditor.FileEditorManagerEvent) Library(com.intellij.openapi.roots.libraries.Library) Task(com.intellij.openapi.progress.Task) DartProblemsView(com.jetbrains.lang.dart.ide.errorTreeView.DartProblemsView) ApplicationInfo(com.intellij.openapi.application.ApplicationInfo) ApplicationNamesInfo(com.intellij.openapi.application.ApplicationNamesInfo) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) org.dartlang.analysis.server.protocol(org.dartlang.analysis.server.protocol) DebugPrintStream(com.google.dart.server.internal.remote.DebugPrintStream) DartSdkUpdateChecker(com.jetbrains.lang.dart.sdk.DartSdkUpdateChecker) RemoteAnalysisServerImpl(com.google.dart.server.internal.remote.RemoteAnalysisServerImpl) ProgressManager(com.intellij.openapi.progress.ProgressManager) DumbService(com.intellij.openapi.project.DumbService) QueueProcessor(com.intellij.util.concurrency.QueueProcessor) DartYamlFileTypeFactory(com.jetbrains.lang.dart.DartYamlFileTypeFactory) AnalysisServer(com.google.dart.server.generated.AnalysisServer) DartSdkUtil(com.jetbrains.lang.dart.sdk.DartSdkUtil) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) DartBundle(com.jetbrains.lang.dart.DartBundle) Nullable(org.jetbrains.annotations.Nullable) CountDownLatch(java.util.concurrent.CountDownLatch) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Contract(org.jetbrains.annotations.Contract) ServiceManager(com.intellij.openapi.components.ServiceManager) DartPubActionBase(com.jetbrains.lang.dart.ide.actions.DartPubActionBase) EditorFactory(com.intellij.openapi.editor.EditorFactory) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Registry(com.intellij.openapi.util.registry.Registry) com.intellij.util(com.intellij.util) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) Consumer(com.intellij.util.Consumer) DartFileListener(com.jetbrains.lang.dart.DartFileListener) com.google.dart.server(com.google.dart.server) DocumentListener(com.intellij.openapi.editor.event.DocumentListener) java.util(java.util) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) FilenameIndex(com.intellij.psi.search.FilenameIndex) StdioServerSocket(com.google.dart.server.internal.remote.StdioServerSocket) SearchScope(com.intellij.psi.search.SearchScope) ContainerUtil(com.intellij.util.containers.ContainerUtil) DartQuickAssistIntention(com.jetbrains.lang.dart.assists.DartQuickAssistIntention) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) Lists(com.google.common.collect.Lists) Comparing(com.intellij.openapi.util.Comparing) EvictingQueue(com.google.common.collect.EvictingQueue) IntentionManager(com.intellij.codeInsight.intention.IntentionManager) Project(com.intellij.openapi.project.Project) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) DartSdkLibUtil(com.jetbrains.lang.dart.sdk.DartSdkLibUtil) StringUtil(com.intellij.openapi.util.text.StringUtil) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) Disposable(com.intellij.openapi.Disposable) File(java.io.File) DartFeedbackBuilder(com.jetbrains.lang.dart.ide.errorTreeView.DartFeedbackBuilder) TimeUnit(java.util.concurrent.TimeUnit) PubspecYamlUtil(com.jetbrains.lang.dart.util.PubspecYamlUtil) QuickAssistSet(com.jetbrains.lang.dart.assists.QuickAssistSet) Condition(com.intellij.openapi.util.Condition) QueueProcessor(com.intellij.util.concurrency.QueueProcessor) THashSet(gnu.trove.THashSet) DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) DartFileListener(com.jetbrains.lang.dart.DartFileListener) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module)

Example 24 with DartSdk

use of com.jetbrains.lang.dart.sdk.DartSdk in project intellij-plugins by JetBrains.

the class DartProjectComponent method convertOrderEntriesTargetingGlobalDartSdkLib.

private void convertOrderEntriesTargetingGlobalDartSdkLib() {
    final DartSdk correctSdk = DartSdk.getDartSdk(myProject);
    // already converted
    if (correctSdk != null)
        return;
    // for performance reasons avoid taking write action and modifiable models if not needed
    if (!hasIncorrectModuleDependencies())
        return;
    final String sdkPath = DartSdkUtil.getFirstKnownDartSdkPath();
    if (sdkPath == null)
        return;
    ApplicationManager.getApplication().runWriteAction(() -> {
        DartSdkLibUtil.ensureDartSdkConfigured(myProject, sdkPath);
        final Collection<ModifiableRootModel> modelsToCommit = new SmartList<>();
        for (final Module module : ModuleManager.getInstance(myProject).getModules()) {
            boolean hasCorrectDependency = false;
            boolean needsCorrectDependency = false;
            final List<OrderEntry> orderEntriesToRemove = new SmartList<>();
            final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
            for (final OrderEntry orderEntry : model.getOrderEntries()) {
                if (isOldGlobalDartSdkLibEntry(orderEntry)) {
                    needsCorrectDependency = true;
                    orderEntriesToRemove.add(orderEntry);
                } else if (DartSdkLibUtil.isDartSdkOrderEntry(orderEntry)) {
                    hasCorrectDependency = true;
                }
            }
            if (needsCorrectDependency && !hasCorrectDependency || !orderEntriesToRemove.isEmpty()) {
                if (needsCorrectDependency && !hasCorrectDependency) {
                    model.addInvalidLibrary(DartSdk.DART_SDK_LIB_NAME, LibraryTablesRegistrar.PROJECT_LEVEL);
                }
                for (OrderEntry entry : orderEntriesToRemove) {
                    model.removeOrderEntry(entry);
                }
                modelsToCommit.add(model);
            } else {
                model.dispose();
            }
        }
        commitModifiableModels(myProject, modelsToCommit);
    });
}
Also used : DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) SmartList(com.intellij.util.SmartList) Module(com.intellij.openapi.module.Module)

Example 25 with DartSdk

use of com.jetbrains.lang.dart.sdk.DartSdk in project intellij-plugins by JetBrains.

the class DartServerRootsHandler method updateRoots.

private void updateRoots() {
    final DartSdk sdk = DartSdk.getDartSdk(myProject);
    if (sdk == null || !DartAnalysisServerService.isDartSdkVersionSufficient(sdk)) {
        DartAnalysisServerService.getInstance(myProject).stopServer();
    }
    final List<String> newIncludedRoots = new SmartList<>();
    final List<String> newExcludedRoots = new SmartList<>();
    if (sdk != null) {
        @SuppressWarnings("ConstantConditions") final String dotIdeaPath = PathUtil.getParentPath(myProject.getProjectFilePath());
        if (dotIdeaPath.endsWith("/.idea")) {
            newExcludedRoots.add(FileUtil.toSystemDependentName(dotIdeaPath));
        }
        for (Module module : DartSdkLibUtil.getModulesWithDartSdkEnabled(myProject)) {
            final Set<String> excludedPackageSymlinkUrls = getExcludedPackageSymlinkUrls(module);
            for (ContentEntry contentEntry : ModuleRootManager.getInstance(module).getContentEntries()) {
                final String contentEntryUrl = contentEntry.getUrl();
                if (contentEntryUrl.startsWith(URLUtil.FILE_PROTOCOL + URLUtil.SCHEME_SEPARATOR)) {
                    newIncludedRoots.add(FileUtil.toSystemDependentName(VfsUtilCore.urlToPath(contentEntryUrl)));
                    for (String excludedUrl : contentEntry.getExcludeFolderUrls()) {
                        if (excludedUrl.startsWith(contentEntryUrl) && !excludedPackageSymlinkUrls.contains(excludedUrl)) {
                            newExcludedRoots.add(FileUtil.toSystemDependentName(VfsUtilCore.urlToPath(excludedUrl)));
                        }
                    }
                }
            }
        }
    }
    if (!myIncludedRoots.equals(newIncludedRoots) || !myExcludedRoots.equals(newExcludedRoots)) {
        myIncludedRoots.clear();
        myExcludedRoots.clear();
        if (DartAnalysisServerService.getInstance(myProject).updateRoots(newIncludedRoots, newExcludedRoots)) {
            myIncludedRoots.addAll(newIncludedRoots);
            myExcludedRoots.addAll(newExcludedRoots);
        }
    }
}
Also used : DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) ContentEntry(com.intellij.openapi.roots.ContentEntry) SmartList(com.intellij.util.SmartList) Module(com.intellij.openapi.module.Module)

Aggregations

DartSdk (com.jetbrains.lang.dart.sdk.DartSdk)30 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 Module (com.intellij.openapi.module.Module)8 Nullable (org.jetbrains.annotations.Nullable)8 Project (com.intellij.openapi.project.Project)6 NotNull (org.jetbrains.annotations.NotNull)6 ExecutionException (com.intellij.execution.ExecutionException)4 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)3 EvictingQueue (com.google.common.collect.EvictingQueue)2 Lists (com.google.common.collect.Lists)2 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)2 com.google.dart.server (com.google.dart.server)2 AnalysisServer (com.google.dart.server.generated.AnalysisServer)2 DebugPrintStream (com.google.dart.server.internal.remote.DebugPrintStream)2 RemoteAnalysisServerImpl (com.google.dart.server.internal.remote.RemoteAnalysisServerImpl)2 StdioServerSocket (com.google.dart.server.internal.remote.StdioServerSocket)2 Logging (com.google.dart.server.utilities.logging.Logging)2 IntentionManager (com.intellij.codeInsight.intention.IntentionManager)2 RuntimeConfigurationError (com.intellij.execution.configurations.RuntimeConfigurationError)2 Disposable (com.intellij.openapi.Disposable)2