Search in sources :

Example 6 with PerlHostData

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

the class PerlRunUtil method getPerlCommandLine.

/**
 * Builds non-patched perl command line (without patching by version manager)
 *
 * @return new perl command line or null if sdk is missing or corrupted
 */
@Nullable
public static PerlCommandLine getPerlCommandLine(@NotNull Project project, @Nullable Sdk perlSdk, @Nullable String localScriptPath, @NotNull List<String> perlParameters, @NotNull List<String> scriptParameters) {
    if (perlSdk == null) {
        perlSdk = PerlProjectManager.getSdk(project);
    }
    if (perlSdk == null) {
        LOG.error("No sdk provided or available in project " + project);
        return null;
    }
    String interpreterPath = PerlProjectManager.getInterpreterPath(perlSdk);
    if (StringUtil.isEmpty(interpreterPath)) {
        LOG.warn("Empty interpreter path in " + perlSdk + " while building command line for " + localScriptPath);
        return null;
    }
    PerlCommandLine commandLine = new PerlCommandLine(perlSdk).withProject(project);
    commandLine.setExePath(interpreterPath);
    PerlHostData<?, ?> hostData = PerlHostData.notNullFrom(perlSdk);
    for (VirtualFile libRoot : PerlProjectManager.getInstance(project).getModulesLibraryRoots()) {
        commandLine.addParameter(PERL_I + hostData.getRemotePath(libRoot.getCanonicalPath()));
    }
    commandLine.addParameters(perlParameters);
    if (StringUtil.isNotEmpty(localScriptPath)) {
        String remoteScriptPath = hostData.getRemotePath(localScriptPath);
        if (remoteScriptPath != null) {
            commandLine.addParameter(remoteScriptPath);
        }
    }
    commandLine.addParameters(scriptParameters);
    return commandLine;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PerlCommandLine(com.perl5.lang.perl.idea.execution.PerlCommandLine) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with PerlHostData

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

the class PerlRunUtil method getBinDirectories.

/**
 * @return list of perl bin directories where script from library may be located
 */
@NotNull
public static Stream<VirtualFile> getBinDirectories(@Nullable Sdk sdk) {
    if (sdk == null) {
        return Stream.empty();
    }
    ApplicationManager.getApplication().assertReadAccessAllowed();
    SdkTypeId sdkType = sdk.getSdkType();
    if (!(sdkType instanceof PerlSdkType)) {
        throw new IllegalArgumentException("Got non-perl sdk: " + sdk);
    }
    List<VirtualFile> files = new ArrayList<>(ContainerUtil.map(sdk.getRootProvider().getFiles(OrderRootType.CLASSES), PerlRunUtil::findLibsBin));
    PerlHostData<?, ?> hostData = PerlHostData.notNullFrom(sdk);
    File localSdkBinDir = hostData.getLocalPath(new File(StringUtil.notNullize(PerlProjectManager.getInterpreterPath(sdk))).getParentFile());
    if (localSdkBinDir != null) {
        files.add(VfsUtil.findFileByIoFile(localSdkBinDir, false));
    }
    PerlVersionManagerData.notNullFrom(sdk).getBinDirsPath().forEach(it -> ObjectUtils.doIfNotNull(hostData.getLocalPath(it), localPath -> files.add(VfsUtil.findFileByIoFile(localPath, false))));
    return files.stream().filter(Objects::nonNull).distinct();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CpanminusAdapter(com.perl5.lang.perl.adapters.CpanminusAdapter) PerlBundle(com.perl5.PerlBundle) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PerlTerminalExecutionConsole(com.perl5.lang.perl.idea.execution.PerlTerminalExecutionConsole) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) PerlSdkType(com.perl5.lang.perl.idea.sdk.PerlSdkType) ReadAction(com.intellij.openapi.application.ReadAction) PerlCommandLine(com.perl5.lang.perl.idea.execution.PerlCommandLine) Task(com.intellij.openapi.progress.Task) ConsoleViewContentType(com.intellij.execution.ui.ConsoleViewContentType) Semaphore(com.intellij.util.concurrency.Semaphore) Disposer(com.intellij.openapi.util.Disposer) Logger(com.intellij.openapi.diagnostic.Logger) PerlHostData(com.perl5.lang.perl.idea.sdk.host.PerlHostData) Notifications(com.intellij.notification.Notifications) ProgressManager(com.intellij.openapi.progress.ProgressManager) OrderRootType(com.intellij.openapi.roots.OrderRootType) NotificationType(com.intellij.notification.NotificationType) Notification(com.intellij.notification.Notification) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Contract(org.jetbrains.annotations.Contract) ProcessListener(com.intellij.execution.process.ProcessListener) Stream(java.util.stream.Stream) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ApplicationManager(com.intellij.openapi.application.ApplicationManager) ProcessEvent(com.intellij.execution.process.ProcessEvent) NotNull(org.jetbrains.annotations.NotNull) PerlProjectManager(com.perl5.lang.perl.idea.project.PerlProjectManager) java.util(java.util) WriteAction(com.intellij.openapi.application.WriteAction) PerlVersionManagerData(com.perl5.lang.perl.idea.sdk.versionManager.PerlVersionManagerData) RunContentManager(com.intellij.execution.ui.RunContentManager) ExecutionException(com.intellij.execution.ExecutionException) DaemonCodeAnalyzer(com.intellij.codeInsight.daemon.DaemonCodeAnalyzer) ContainerUtil(com.intellij.util.containers.ContainerUtil) PerlOsHandler(com.perl5.lang.perl.idea.sdk.host.os.PerlOsHandler) PerlRunConsole(com.perl5.lang.perl.idea.run.PerlRunConsole) ProjectRootManagerEx(com.intellij.openapi.roots.ex.ProjectRootManagerEx) PerlIcons(com.perl5.PerlIcons) Project(com.intellij.openapi.project.Project) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) SdkTypeId(com.intellij.openapi.projectRoots.SdkTypeId) StringUtil(com.intellij.openapi.util.text.StringUtil) Key(com.intellij.openapi.util.Key) AnAction(com.intellij.openapi.actionSystem.AnAction) Executor(com.intellij.execution.Executor) Disposable(com.intellij.openapi.Disposable) Sdk(com.intellij.openapi.projectRoots.Sdk) File(java.io.File) ProcessHandler(com.intellij.execution.process.ProcessHandler) TestOnly(org.jetbrains.annotations.TestOnly) CpanAdapter(com.perl5.lang.perl.adapters.CpanAdapter) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) PerlConsoleView(com.perl5.lang.perl.idea.sdk.host.PerlConsoleView) VfsUtil(com.intellij.openapi.vfs.VfsUtil) ObjectUtils(com.intellij.util.ObjectUtils) EmptyRunnable(com.intellij.openapi.util.EmptyRunnable) PerlSdkType(com.perl5.lang.perl.idea.sdk.PerlSdkType) SdkTypeId(com.intellij.openapi.projectRoots.SdkTypeId) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with PerlHostData

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

the class PerlBrewCreateLibraryAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    Sdk perlSdk = PerlProjectManager.getSdk(e);
    PerlBrewData perlBrewData = ObjectUtils.tryCast(PerlVersionManagerData.from(perlSdk), PerlBrewData.class);
    if (perlBrewData == null) {
        return;
    }
    PerlHostData<?, ?> hostData = PerlHostData.from(perlSdk);
    if (hostData == null) {
        return;
    }
    final String perlVersionString = perlBrewData.getPerlVersionString();
    String libraryName = Messages.showInputDialog(getEventProject(e), PerlBundle.message("perl.vm.perlbrew.create.lib.message"), PerlBundle.message("perl.vm.perlbrew.create.lib.title", perlVersionString), null);
    if (StringUtil.isEmpty(libraryName)) {
        return;
    }
    new Task.Backgroundable(e.getProject(), PerlBundle.message("perl.vm.perlbrew.create.lib.progress", libraryName, perlVersionString)) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            PerlBrewAdapter perlBrewAdapter = new PerlBrewAdapter(perlBrewData.getVersionManagerPath(), hostData);
            ProcessOutput processOutput = perlBrewAdapter.createLibrary(perlVersionString, libraryName);
            if (processOutput == null) {
                return;
            }
            String distirbutionId = perlVersionString + "@" + libraryName;
            if (processOutput.getExitCode() == 0) {
                doCreateSdk(perlBrewAdapter, distirbutionId);
            }
            if (StringUtil.contains(processOutput.getStderr(), "is already there")) {
                Ref<Integer> resultRef = Ref.create(-1);
                ApplicationManager.getApplication().invokeAndWait(() -> resultRef.set(Messages.showYesNoDialog(PerlBundle.message("perl.vm.perlbrew.library.exists", distirbutionId), PerlBundle.message("perl.vm.perlbrew.title"), PerlIcons.PERLBREW_ICON)));
                if (Messages.YES == resultRef.get()) {
                    doCreateSdk(perlBrewAdapter, distirbutionId);
                }
            }
        }

        // fixme we could avoid creating duplicated sdks here
        private void doCreateSdk(@NotNull PerlBrewAdapter perlBrewAdapter, @NotNull String distirbutionId) {
            PerlBrewHandler.getInstance().createInterpreter(distirbutionId, perlBrewAdapter, sdk -> ApplicationManager.getApplication().invokeLater(() -> {
                PerlBrewData perlBrewData = PerlBrewData.from(sdk);
                if (perlBrewData != null && myProject != null && Messages.showYesNoDialog(myProject, PerlBundle.message("perl.vm.perlbrew.create.lib.select", perlBrewData.getDistributionId()), PerlBundle.message("perl.vm.perlbrew.create.lib.title", perlBrewData.getPerlVersionString()), null) == Messages.YES) {
                    PerlProjectManager.getInstance(myProject).setProjectSdk(sdk);
                }
            }), myProject);
        }
    }.queue();
}
Also used : PerlProjectManager(com.perl5.lang.perl.idea.project.PerlProjectManager) PerlVersionManagerData(com.perl5.lang.perl.idea.sdk.versionManager.PerlVersionManagerData) PerlBundle(com.perl5.PerlBundle) StringUtil(com.intellij.openapi.util.text.StringUtil) Sdk(com.intellij.openapi.projectRoots.Sdk) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Task(com.intellij.openapi.progress.Task) PerlIcons(com.perl5.PerlIcons) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ProcessOutput(com.intellij.execution.process.ProcessOutput) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Messages(com.intellij.openapi.ui.Messages) ObjectUtils(com.intellij.util.ObjectUtils) DumbAware(com.intellij.openapi.project.DumbAware) PerlHostData(com.perl5.lang.perl.idea.sdk.host.PerlHostData) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) Task(com.intellij.openapi.progress.Task) Ref(com.intellij.openapi.util.Ref) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ProcessOutput(com.intellij.execution.process.ProcessOutput) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 9 with PerlHostData

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

the class PerlProfilerRunProfileState method getAdditionalEnvironmentVariables.

@Override
public Map<String, String> getAdditionalEnvironmentVariables() throws ExecutionException {
    Sdk effectiveSdk = ((GenericPerlRunConfiguration) getEnvironment().getRunProfile()).getEffectiveSdk();
    PerlHostData<?, ?> hostData = PerlHostData.notNullFrom(effectiveSdk);
    var dumpLocalPath = getDumpFile().getAbsolutePath();
    var remotePath = hostData.getRemotePath(dumpLocalPath);
    if (StringUtil.isEmpty(remotePath)) {
        throw new ExecutionException("Unable to compute remote path for: " + dumpLocalPath);
    }
    var nytProfOptions = "stmts=0:calls=2:savesrc=0:slowops=1:sigexit=1:addpid=1" + ":file=" + StringUtil.escapeChar(FileUtil.toSystemIndependentName(remotePath), ':') + ":start=" + myProfilerConfigurationState.getStartupMode().getProfilerCommand();
    if (myProfilerConfigurationState.isOptimizerDisabled()) {
        nytProfOptions += ":optimize=0";
    }
    return Map.of("NYTPROF", nytProfOptions);
}
Also used : Sdk(com.intellij.openapi.projectRoots.Sdk) GenericPerlRunConfiguration(com.perl5.lang.perl.idea.run.GenericPerlRunConfiguration) ExecutionException(com.intellij.execution.ExecutionException)

Example 10 with PerlHostData

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

the class PerlHostHandler method chooseFileInteractively.

/**
 * Chooses a path conforming with {@code pathPredicate} on user-selected host and passes selected path and host data
 * to the {@code selectionConsumer}
 *
 * @param defaultPathFunction function computing a default path from {@code hostData}
 * @param useDefaultIfExists  true if default path should be used silently if exists
 * @param nameValidator       restricts visible file names
 * @param pathValidator       validates a path selected by user and returns error message or null if everything is fine
 * @param selectionConsumer   a callback for selected result. Accepts path selected and the host data
 * @param disposable          session-bound things may be attached to this disposable, which is going to be disposed by parent configurable
 */
public void chooseFileInteractively(@NotNull String dialogTitle, @Nullable Function<PerlHostData<?, ?>, File> defaultPathFunction, boolean useDefaultIfExists, @NotNull Predicate<String> nameValidator, @NotNull Function<String, String> pathValidator, @NotNull BiConsumer<String, PerlHostData<?, ?>> selectionConsumer, @NotNull Disposable disposable) {
    Data hostData = createDataInteractively();
    if (hostData == null) {
        return;
    }
    VirtualFileSystem fileSystem = hostData.getFileSystem(disposable);
    File defaultPath = defaultPathFunction == null ? null : defaultPathFunction.apply(hostData);
    Consumer<String> resultConsumer = it -> selectionConsumer.accept(it, hostData);
    if (fileSystem != null) {
        chooseFileInteractively(dialogTitle, defaultPath, useDefaultIfExists, nameValidator, pathValidator, resultConsumer, hostData, fileSystem);
    } else {
        chooseFileInteractively(dialogTitle, defaultPath, useDefaultIfExists, nameValidator, pathValidator, resultConsumer, hostData);
    }
}
Also used : AbstractPerlHandler(com.perl5.lang.perl.idea.sdk.AbstractPerlHandler) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Function(java.util.function.Function) PerlOsHandler(com.perl5.lang.perl.idea.sdk.host.os.PerlOsHandler) PerlHandlerBean(com.perl5.lang.perl.idea.sdk.PerlHandlerBean) BiConsumer(java.util.function.BiConsumer) Project(com.intellij.openapi.project.Project) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) Messages(com.intellij.openapi.ui.Messages) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) UnnamedConfigurable(com.intellij.openapi.options.UnnamedConfigurable) StringUtil(com.intellij.openapi.util.text.StringUtil) Predicate(java.util.function.Predicate) PerlHandlerCollector(com.perl5.lang.perl.idea.sdk.PerlHandlerCollector) Disposable(com.intellij.openapi.Disposable) Sdk(com.intellij.openapi.projectRoots.Sdk) File(java.io.File) Objects(java.util.Objects) Consumer(java.util.function.Consumer) Nullable(org.jetbrains.annotations.Nullable) Contract(org.jetbrains.annotations.Contract) List(java.util.List) Stream(java.util.stream.Stream) VirtualFileSystem(com.intellij.openapi.vfs.VirtualFileSystem) InputValidator(com.intellij.openapi.ui.InputValidator) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) Element(org.jdom.Element) FileChooser(com.intellij.openapi.fileChooser.FileChooser) javax.swing(javax.swing) VirtualFileSystem(com.intellij.openapi.vfs.VirtualFileSystem) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

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