Search in sources :

Example 1 with PerlOsHandler

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

the class PerlRunUtil method findScript.

/**
 * Attempts to find a script by name in perl's libraries path
 *
 * @param sdk        perl sdk to search in
 * @param scriptName script name to find
 * @return script's virtual file if available
 * @apiNote returns virtual file of local file, not remote
 */
@Contract("null,_->null; _,null->null")
@Nullable
public static VirtualFile findScript(@Nullable Sdk sdk, @Nullable String scriptName) {
    if (sdk == null || StringUtil.isEmpty(scriptName)) {
        return null;
    }
    ApplicationManager.getApplication().assertReadAccessAllowed();
    PerlOsHandler osHandler = PerlOsHandler.notNullFrom(sdk);
    return getBinDirectories(sdk).map(root -> {
        VirtualFile scriptFile = null;
        if (osHandler.isMsWindows()) {
            scriptFile = root.findChild(scriptName + ".bat");
        }
        return scriptFile != null ? scriptFile : root.findChild(scriptName);
    }).filter(Objects::nonNull).findFirst().orElse(null);
}
Also used : 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) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PerlOsHandler(com.perl5.lang.perl.idea.sdk.host.os.PerlOsHandler) Contract(org.jetbrains.annotations.Contract) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

DaemonCodeAnalyzer (com.intellij.codeInsight.daemon.DaemonCodeAnalyzer)1 ExecutionException (com.intellij.execution.ExecutionException)1 Executor (com.intellij.execution.Executor)1 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)1 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)1 ProcessEvent (com.intellij.execution.process.ProcessEvent)1 ProcessHandler (com.intellij.execution.process.ProcessHandler)1 ProcessListener (com.intellij.execution.process.ProcessListener)1 ConsoleViewContentType (com.intellij.execution.ui.ConsoleViewContentType)1 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)1 RunContentManager (com.intellij.execution.ui.RunContentManager)1 Notification (com.intellij.notification.Notification)1 NotificationType (com.intellij.notification.NotificationType)1 Notifications (com.intellij.notification.Notifications)1 Disposable (com.intellij.openapi.Disposable)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ReadAction (com.intellij.openapi.application.ReadAction)1 WriteAction (com.intellij.openapi.application.WriteAction)1