Search in sources :

Example 11 with DartSdk

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

the class DartSdkConfigurationTest method testSdkRootsUsingBlacklist.

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

Example 12 with DartSdk

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

the class AbstractDartFileProcessingAction method update.

@Override
public void update(final AnActionEvent event) {
    final Presentation presentation = event.getPresentation();
    final Project project = event.getProject();
    if (project == null) {
        presentation.setEnabledAndVisible(false);
        return;
    }
    final DartSdk sdk = DartSdk.getDartSdk(project);
    if (sdk == null || !DartAnalysisServerService.isDartSdkVersionSufficient(sdk)) {
        presentation.setEnabledAndVisible(false);
        return;
    }
    final Editor editor = event.getData(CommonDataKeys.EDITOR);
    if (editor != null) {
        final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
        // visible for any Dart file, but enabled for applicable only
        presentation.setVisible(psiFile != null && psiFile.getFileType() == DartFileType.INSTANCE);
        presentation.setEnabled(isApplicableFile(psiFile));
        presentation.setText(getActionTextForEditor());
        return;
    }
    final VirtualFile[] filesAndDirs = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(event.getDataContext());
    if (filesAndDirs == null) {
        presentation.setEnabledAndVisible(false);
        return;
    }
    presentation.setEnabledAndVisible(mayHaveApplicableDartFiles(project, filesAndDirs));
    presentation.setText(getActionTextForFiles());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) PsiFile(com.intellij.psi.PsiFile) Presentation(com.intellij.openapi.actionSystem.Presentation) Editor(com.intellij.openapi.editor.Editor)

Example 13 with DartSdk

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

the class DartCoverageProgramRunner method doExecute.

@Nullable
@Override
protected RunContentDescriptor doExecute(@NotNull final RunProfileState state, @NotNull final ExecutionEnvironment env) throws ExecutionException {
    FileDocumentManager.getInstance().saveAllDocuments();
    final DartCommandLineRunConfiguration runConfiguration = (DartCommandLineRunConfiguration) env.getRunProfile();
    final DartSdk sdk = DartSdk.getDartSdk(runConfiguration.getProject());
    if (sdk == null) {
        throw new ExecutionException(DartBundle.message("dart.sdk.is.not.configured"));
    }
    final String dartPubPath = DartSdkUtil.getPubPath(sdk);
    final RunContentDescriptor result = DefaultProgramRunnerKt.executeState(state, env, this);
    if (result == null) {
        return null;
    }
    if (!myCoveragePackageActivated && !activateCoverage(runConfiguration.getProject(), dartPubPath)) {
        throw new ExecutionException("Cannot activate pub package 'coverage'.");
    }
    final ProcessHandler dartAppProcessHandler = result.getProcessHandler();
    if (dartAppProcessHandler != null) {
        ((DartCommandLineRunningState) state).addObservatoryUrlConsumer(observatoryUrl -> startCollectingCoverage(env, dartAppProcessHandler, observatoryUrl));
    }
    return result;
}
Also used : DartCommandLineRunningState(com.jetbrains.lang.dart.ide.runner.server.DartCommandLineRunningState) DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) DartCommandLineRunConfiguration(com.jetbrains.lang.dart.ide.runner.server.DartCommandLineRunConfiguration) ExecutionException(com.intellij.execution.ExecutionException) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with DartSdk

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

the class AbstractDartFileProcessingAction method actionPerformed.

@Override
public void actionPerformed(final AnActionEvent event) {
    final Project project = event.getProject();
    if (project == null)
        return;
    final DartSdk sdk = DartSdk.getDartSdk(project);
    if (sdk == null || !DartAnalysisServerService.isDartSdkVersionSufficient(sdk))
        return;
    PsiDocumentManager.getInstance(project).commitAllDocuments();
    final Editor editor = event.getData(CommonDataKeys.EDITOR);
    if (editor != null) {
        final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
        if (!isApplicableFile(psiFile))
            return;
        runOverEditor(project, editor, psiFile);
    } else {
        final VirtualFile[] filesAndDirs = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(event.getDataContext());
        if (filesAndDirs != null && DartAnalysisServerService.getInstance(project).serverReadyForRequest(project)) {
            final List<VirtualFile> files = getApplicableVirtualFiles(project, filesAndDirs);
            runOverFiles(project, files);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor)

Example 15 with DartSdk

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

the class DartPubActionBase method performPubAction.

public void performPubAction(@NotNull final Module module, @NotNull final VirtualFile pubspecYamlFile, final boolean allowModalDialogs) {
    DartSdk sdk = DartSdk.getDartSdk(module.getProject());
    if (sdk == null && allowModalDialogs) {
        final int answer = Messages.showDialog(module.getProject(), DartBundle.message("dart.sdk.is.not.configured"), getTitle(pubspecYamlFile), new String[] { DartBundle.message("setup.dart.sdk"), CommonBundle.getCancelButtonText() }, Messages.OK, Messages.getErrorIcon());
        if (answer != Messages.OK)
            return;
        DartConfigurable.openDartSettings(module.getProject());
        sdk = DartSdk.getDartSdk(module.getProject());
    }
    if (sdk == null)
        return;
    File pubFile = new File(DartSdkUtil.getPubPath(sdk));
    if (!pubFile.isFile() && allowModalDialogs) {
        final int answer = Messages.showDialog(module.getProject(), DartBundle.message("dart.sdk.bad.dartpub.path", pubFile.getPath()), getTitle(pubspecYamlFile), new String[] { DartBundle.message("setup.dart.sdk"), CommonBundle.getCancelButtonText() }, Messages.OK, Messages.getErrorIcon());
        if (answer != Messages.OK)
            return;
        DartConfigurable.openDartSettings(module.getProject());
        sdk = DartSdk.getDartSdk(module.getProject());
        if (sdk == null)
            return;
        pubFile = new File(DartSdkUtil.getPubPath(sdk));
    }
    if (!pubFile.isFile())
        return;
    final String[] pubParameters = calculatePubParameters(module.getProject(), pubspecYamlFile);
    if (pubParameters != null) {
        final GeneralCommandLine command = new GeneralCommandLine().withWorkDirectory(pubspecYamlFile.getParent().getPath());
        if (FlutterUtil.isFlutterModule(module)) {
            final String flutterRoot = FlutterUtil.getFlutterRoot(sdk.getHomePath());
            if (flutterRoot != null) {
                command.getEnvironment().put("FLUTTER_ROOT", FileUtil.toSystemDependentName(flutterRoot));
            }
        }
        command.setExePath(pubFile.getPath());
        command.addParameters(pubParameters);
        doPerformPubAction(module, pubspecYamlFile, command, getTitle(pubspecYamlFile));
    }
}
Also used : DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File)

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