Search in sources :

Example 11 with PerlHostData

use of com.perl5.lang.perl.idea.sdk.host.PerlHostData in project Perl5-IDEA by Camelcade.

the class PerlTestRunConfiguration method createBaseCommandLine.

@Override
@NotNull
protected PerlCommandLine createBaseCommandLine(@NotNull PerlRunProfileState perlRunProfileState) throws ExecutionException {
    ExecutionEnvironment executionEnvironment = perlRunProfileState.getEnvironment();
    Project project = executionEnvironment.getProject();
    List<String> additionalPerlParameters = perlRunProfileState.getAdditionalPerlParameters(this);
    Map<String, String> additionalEnvironmentVariables = perlRunProfileState.getAdditionalEnvironmentVariables();
    Sdk perlSdk = getEffectiveSdk();
    VirtualFile proveScript = PerlRunUtil.findLibraryScriptWithNotification(perlSdk, getProject(), PROVE, TEST_HARNESS);
    if (proveScript == null) {
        throw new ExecutionException(PerlBundle.message("perl.run.error.prove.missing", perlSdk.getName()));
    }
    PerlHostData<?, ?> perlHostData = PerlHostData.notNullFrom(perlSdk);
    Set<String> proveParameters = new LinkedHashSet<>(PROVE_DEFAULT_PARAMETERS);
    proveParameters.addAll(getScriptParameters());
    proveParameters.add(PROVE_JOBS_PARAMETER);
    proveParameters.add(Integer.toString(perlRunProfileState.isParallelRunAllowed() ? getJobsNumber() : 1));
    VirtualFile workingDirectory = computeExplicitWorkingDirectory();
    List<String> testsPaths = new ArrayList<>();
    for (VirtualFile testVirtualFile : computeTargetFiles()) {
        if (testVirtualFile == null) {
            continue;
        }
        String virtualFilePath = testVirtualFile.getPath();
        if (workingDirectory != null && VfsUtil.isAncestor(workingDirectory, testVirtualFile, true)) {
            testsPaths.add(VfsUtil.getRelativePath(testVirtualFile, workingDirectory));
        } else {
            testsPaths.add(perlHostData.getRemotePath(virtualFilePath));
        }
    }
    String remotePath = perlHostData.getRemotePath(proveScript.getPath());
    if (StringUtil.isEmpty(remotePath)) {
        throw new ExecutionException("Unable to map remote path: " + remotePath + " for " + perlHostData);
    }
    PerlCommandLine commandLine = new PerlCommandLine(getEffectiveInterpreterPath()).withParameters(remotePath).withParameters(proveParameters).withParameters(testsPaths).withProject(project).withSdk(perlSdk);
    List<String> testScriptParametersList = getTestScriptParametersList();
    if (!testScriptParametersList.isEmpty()) {
        commandLine.withParameters("::");
        commandLine.withParameters(testScriptParametersList);
    }
    ArrayList<String> perlParametersList = new ArrayList<>(getPerlParametersList());
    perlParametersList.addAll(additionalPerlParameters);
    for (VirtualFile libRoot : PerlProjectManager.getInstance(project).getModulesLibraryRoots()) {
        perlParametersList.add(PERL_I + perlHostData.getRemotePath(libRoot.getCanonicalPath()));
    }
    // environment
    Map<String, String> environment = new HashMap<>(getEnvs());
    environment.putAll(additionalEnvironmentVariables);
    if (!perlParametersList.isEmpty()) {
        String currentOpt = environment.get(PerlRunUtil.PERL5OPT);
        if (StringUtil.isNotEmpty(currentOpt)) {
            perlParametersList.addAll(0, StringUtil.split(currentOpt, " "));
        }
        environment.put(PerlRunUtil.PERL5OPT, StringUtil.join(perlParametersList, " "));
    }
    environment.forEach((key, val) -> commandLine.withEnvironment(PROVE_PASS_PREFIX + key, val));
    commandLine.withParentEnvironmentType(isPassParentEnvs() ? CONSOLE : NONE);
    return commandLine;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) Project(com.intellij.openapi.project.Project) PerlCommandLine(com.perl5.lang.perl.idea.execution.PerlCommandLine) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with PerlHostData

use of com.perl5.lang.perl.idea.sdk.host.PerlHostData in project Perl5-IDEA by Camelcade.

the class InstallPerlHandler method doInstall.

void doInstall(@NotNull PerlHostData<?, ?> hostData, @Nullable Project project) {
    if (ApplicationManager.getApplication().isDispatchThread()) {
        throw new RuntimeException("Should not be invoked on EDT");
    }
    PerlVersionManagerAdapter vmAdapter = createAdapter(myVersionManagerPath, hostData);
    PerlRunUtil.setProgressText(PerlBundle.message("perl.vm.fetching.available.perls"));
    List<String> distributionsList = vmAdapter.getInstallableDistributionsList();
    if (distributionsList == null) {
        return;
    }
    ApplicationManager.getApplication().invokeLater(() -> {
        PerlInstallFormOptions optionsForm = createOptionsForm();
        MyDialog dialog = new MyDialog(project, optionsForm, distributionsList);
        if (dialog.showAndGet()) {
            PerlInstallForm installForm = dialog.getForm();
            boolean createInterpreter = installForm.isAddInstalledPerl();
            boolean chooseInterpreter = installForm.isChooseInstalledPerl();
            String distributionId = installForm.getSelectedDistributionId();
            String targetName = optionsForm.getTargetName(distributionId);
            vmAdapter.installPerl(project, distributionId, optionsForm.buildParametersList(), new ProcessAdapter() {

                @Override
                public void processTerminated(@NotNull ProcessEvent event) {
                    if (!createInterpreter || event.getExitCode() != 0) {
                        return;
                    }
                    myVersionManageHandler.createInterpreter(targetName, vmAdapter, sdk -> {
                        if (chooseInterpreter && project != null) {
                            ApplicationManager.getApplication().invokeLater(() -> PerlProjectManager.getInstance(project).setProjectSdk(sdk));
                        }
                    }, project);
                }
            });
        }
    });
}
Also used : PerlProjectManager(com.perl5.lang.perl.idea.project.PerlProjectManager) PerlBundle(com.perl5.PerlBundle) StringUtil(com.intellij.openapi.util.text.StringUtil) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) VersionComparatorUtil(com.intellij.util.text.VersionComparatorUtil) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) Task(com.intellij.openapi.progress.Task) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) PerlIcons(com.perl5.PerlIcons) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Project(com.intellij.openapi.project.Project) ProcessEvent(com.intellij.execution.process.ProcessEvent) PerlRunUtil(com.perl5.lang.perl.util.PerlRunUtil) PerlHostData(com.perl5.lang.perl.idea.sdk.host.PerlHostData) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)9 Sdk (com.intellij.openapi.projectRoots.Sdk)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 Nullable (org.jetbrains.annotations.Nullable)7 Project (com.intellij.openapi.project.Project)6 ExecutionException (com.intellij.execution.ExecutionException)5 ApplicationManager (com.intellij.openapi.application.ApplicationManager)5 StringUtil (com.intellij.openapi.util.text.StringUtil)5 PerlCommandLine (com.perl5.lang.perl.idea.execution.PerlCommandLine)5 PerlBundle (com.perl5.PerlBundle)4 PerlIcons (com.perl5.PerlIcons)4 PerlProjectManager (com.perl5.lang.perl.idea.project.PerlProjectManager)4 PerlHostData (com.perl5.lang.perl.idea.sdk.host.PerlHostData)4 File (java.io.File)4 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)3 ProcessEvent (com.intellij.execution.process.ProcessEvent)3 Logger (com.intellij.openapi.diagnostic.Logger)3 ObjectUtils (com.intellij.util.ObjectUtils)3 ProcessOutput (com.intellij.execution.process.ProcessOutput)2 Notification (com.intellij.notification.Notification)2