Search in sources :

Example 1 with PerlHostData

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

the class PerlCoverageProfileState method getAdditionalPerlParameters.

@Override
@NotNull
public List<String> getAdditionalPerlParameters(@NotNull GenericPerlRunConfiguration perlRunConfiguration) throws ExecutionException {
    CoverageHelper.resetCoverageSuit(perlRunConfiguration);
    String coverageBasePath = CoverageEnabledConfiguration.getOrCreate((GenericPerlRunConfiguration) getEnvironment().getRunProfile()).getCoverageFilePath();
    if (coverageBasePath != null) {
        File coverageDir = new File(coverageBasePath);
        coverageDir.mkdirs();
        LOG.debug("Coverage directory created: ", coverageDir);
    }
    Sdk effectiveSdk = perlRunConfiguration.getEffectiveSdk();
    PerlHostData<?, ?> hostData = PerlHostData.notNullFrom(effectiveSdk);
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        return Collections.singletonList("-MDevel::Cover=-db," + hostData.getRemotePath(coverageBasePath) + ",-dir,.");
    }
    return Collections.singletonList("-MDevel::Cover=-silent,1,-db," + hostData.getRemotePath(coverageBasePath) + ",-dir,.");
}
Also used : GenericPerlRunConfiguration(com.perl5.lang.perl.idea.run.GenericPerlRunConfiguration) Sdk(com.intellij.openapi.projectRoots.Sdk) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PerlHostData

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

the class PerlCoverageRunner method doLoadCoverageData.

@Nullable
private static ProjectData doLoadCoverageData(@NotNull File sessionDataFile, @NotNull PerlCoverageSuite perlCoverageSuite) {
    Project project = perlCoverageSuite.getProject();
    Sdk effectiveSdk;
    try {
        effectiveSdk = perlCoverageSuite.getConfiguration().getEffectiveSdk();
    } catch (ExecutionException e) {
        LOG.error(e);
        return null;
    }
    PerlHostData<?, ?> hostData = PerlHostData.from(effectiveSdk);
    if (hostData == null) {
        LOG.warn("No host data for " + effectiveSdk);
        return null;
    }
    try {
        hostData.fixPermissionsRecursively(sessionDataFile.getAbsolutePath(), project);
    } catch (ExecutionException e) {
        LOG.warn("Error fixing permissions for " + sessionDataFile);
    }
    PerlCommandLine perlCommandLine = ReadAction.compute(() -> {
        if (project.isDisposed()) {
            LOG.debug("Project disposed");
            return null;
        }
        VirtualFile coverFile = PerlRunUtil.findLibraryScriptWithNotification(effectiveSdk, project, COVER, COVER_LIB);
        if (coverFile == null) {
            LOG.warn("No `cover` script found in " + effectiveSdk);
            return null;
        }
        PerlCommandLine commandLine = PerlRunUtil.getPerlCommandLine(project, effectiveSdk, coverFile, Collections.singletonList(PerlRunUtil.PERL_I + hostData.getRemotePath(PerlPluginUtil.getHelpersLibPath())), Collections.emptyList());
        if (commandLine == null) {
            LOG.warn("Unable to create a command line: " + " project: " + project + "; sdk:" + effectiveSdk + "; coverageFile: " + coverFile);
            return null;
        }
        String remotePath = hostData.getRemotePath(sessionDataFile.getAbsolutePath());
        if (StringUtil.isEmpty(remotePath)) {
            LOG.warn("Unable to map remote path for: " + sessionDataFile.getAbsolutePath() + " in " + hostData);
            return null;
        }
        commandLine.addParameters("--silent", "--nosummary", "-report", "camelcade", remotePath);
        commandLine.withSdk(effectiveSdk);
        commandLine.withProject(project);
        return commandLine;
    });
    if (perlCommandLine == null) {
        return null;
    }
    try {
        LOG.info("Loading coverage by: " + perlCommandLine.getCommandLineString());
        ProcessOutput output = PerlHostData.execAndGetOutput(perlCommandLine);
        if (output.getExitCode() != 0) {
            String errorMessage = output.getStderr();
            if (StringUtil.isEmpty(errorMessage)) {
                errorMessage = output.getStdout();
            }
            if (!StringUtil.isEmpty(errorMessage)) {
                showError(project, errorMessage);
            }
            return null;
        }
        String stdout = output.getStdout();
        if (StringUtil.isEmpty(stdout)) {
            return null;
        }
        try {
            PerlFileCoverageData[] filesData = new Gson().fromJson(stdout, PerlFileCoverageData[].class);
            if (filesData != null) {
                return parsePerlFileData(PerlHostData.notNullFrom(effectiveSdk), filesData);
            }
        } catch (JsonParseException e) {
            LOG.warn("Error parsing JSON", e);
            showError(project, e.getMessage());
        }
    } catch (ExecutionException e) {
        LOG.warn("Error loading coverage", e);
        showError(project, e.getMessage());
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ProcessOutput(com.intellij.execution.process.ProcessOutput) PerlCommandLine(com.perl5.lang.perl.idea.execution.PerlCommandLine) Gson(com.google.gson.Gson) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException) JsonParseException(com.google.gson.JsonParseException) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with PerlHostData

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

the class PerlSdkType method setupSdkPaths.

@Override
public void setupSdkPaths(@NotNull Sdk sdk) {
    if (ApplicationManager.getApplication().isDispatchThread() && !ApplicationManager.getApplication().isHeadlessEnvironment()) {
        throw new RuntimeException("Do not call from EDT, refreshes FS");
    }
    String oldText = PerlRunUtil.setProgressText(PerlBundle.message("perl.progress.refreshing.inc", sdk.getName()));
    LOG.info("Refreshing @INC for " + sdk);
    PerlHostData<?, ?> hostData = PerlHostData.notNullFrom(sdk);
    List<String> pathsToRefresh = new ArrayList<>();
    // syncing data if necessary
    List<String> incPaths = computeIncPaths(sdk);
    List<Exception> exceptions = new ArrayList<>();
    try (PerlHostFileTransfer<?> fileTransfer = hostData.getFileTransfer()) {
        Consumer<File> downloader = it -> syncAndCollectException(fileTransfer, it, pathsToRefresh, exceptions, false);
        Consumer<File> binStubber = it -> syncAndCollectException(fileTransfer, it, pathsToRefresh, exceptions, true);
        for (String hostPath : incPaths) {
            downloader.accept(new File(hostPath));
            binStubber.accept(PerlRunUtil.findLibsBin(new File(hostPath)));
        }
        // additional bin dirs from version manager
        PerlVersionManagerData.notNullFrom(sdk).getBinDirsPath().forEach(binStubber);
        // sdk home path
        File interpreterPath = new File(Objects.requireNonNull(PerlProjectManager.getInterpreterPath(sdk)));
        binStubber.accept(interpreterPath.getParentFile());
        List<VirtualFile> filesToRefresh = pathsToRefresh.stream().map(it -> VfsUtil.findFileByIoFile(new File(it), true)).filter(Objects::nonNull).collect(Collectors.toList());
        if (!filesToRefresh.isEmpty()) {
            PerlRunUtil.setProgressText(PerlBundle.message("perl.progress.refreshing.filesystem"));
            VfsUtil.markDirtyAndRefresh(false, true, true, filesToRefresh.toArray(VirtualFile.EMPTY_ARRAY));
        }
        try {
            fileTransfer.syncHelpers();
        } catch (IOException e) {
            exceptions.add(e);
        }
        if (!exceptions.isEmpty()) {
            int copiedFiles = filesToRefresh.size();
            int errorsNumber = exceptions.size();
            Notifications.Bus.notify(new Notification(PerlBundle.message("perl.sync.notification.group"), PerlBundle.message("perl.sync.notification.title"), PerlBundle.message("perl.sync.notification.body", copiedFiles, copiedFiles + errorsNumber, errorsNumber, StringUtil.pluralize(PerlBundle.message("perl.sync.notification.pluralize"), errorsNumber)), NotificationType.ERROR));
            exceptions.forEach(LOG::warn);
        }
    } catch (IOException e) {
        LOG.warn("Error closing transfer for " + sdk, e);
    }
    // updating sdk
    SdkModificator sdkModificator = sdk.getSdkModificator();
    sdkModificator.removeAllRoots();
    for (String hostPath : incPaths) {
        String localPath = hostData.getLocalPath(hostPath);
        if (localPath == null) {
            continue;
        }
        File libDir = new File(localPath);
        if (libDir.exists() && libDir.isDirectory()) {
            VirtualFile virtualDir = VfsUtil.findFileByIoFile(libDir, true);
            if (virtualDir != null) {
                sdkModificator.addRoot(virtualDir, OrderRootType.CLASSES);
            }
        }
    }
    ApplicationManager.getApplication().invokeAndWait(sdkModificator::commitChanges);
    PerlRunUtil.setProgressText(oldText);
}
Also used : PerlProjectManager(com.perl5.lang.perl.idea.project.PerlProjectManager) PerlVersionManagerData(com.perl5.lang.perl.idea.sdk.versionManager.PerlVersionManagerData) PerlBundle(com.perl5.PerlBundle) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PerlHostFileTransfer(com.perl5.lang.perl.idea.sdk.host.PerlHostFileTransfer) ContainerUtil(com.intellij.util.containers.ContainerUtil) ArrayList(java.util.ArrayList) PerlIcons(com.perl5.PerlIcons) com.intellij.openapi.projectRoots(com.intellij.openapi.projectRoots) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) PerlRunUtil(com.perl5.lang.perl.util.PerlRunUtil) Logger(com.intellij.openapi.diagnostic.Logger) PerlSdkTable(com.intellij.openapi.projectRoots.impl.PerlSdkTable) PerlHostData(com.perl5.lang.perl.idea.sdk.host.PerlHostData) ProjectJdkImpl(com.intellij.openapi.projectRoots.impl.ProjectJdkImpl) Notifications(com.intellij.notification.Notifications) OrderRootType(com.intellij.openapi.roots.OrderRootType) SdkConfigurationUtil(com.intellij.openapi.projectRoots.impl.SdkConfigurationUtil) StringUtil(com.intellij.openapi.util.text.StringUtil) PerlImplementationHandler(com.perl5.lang.perl.idea.sdk.implementation.PerlImplementationHandler) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) SystemInfo(com.intellij.openapi.util.SystemInfo) File(java.io.File) NotificationType(com.intellij.notification.NotificationType) Objects(java.util.Objects) Consumer(java.util.function.Consumer) Notification(com.intellij.notification.Notification) Nullable(org.jetbrains.annotations.Nullable) Contract(org.jetbrains.annotations.Contract) List(java.util.List) PerlImplementationData(com.perl5.lang.perl.idea.sdk.implementation.PerlImplementationData) ApplicationManager(com.intellij.openapi.application.ApplicationManager) VfsUtil(com.intellij.openapi.vfs.VfsUtil) ObjectUtils(com.intellij.util.ObjectUtils) NotNull(org.jetbrains.annotations.NotNull) Element(org.jdom.Element) javax.swing(javax.swing) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IOException(java.io.IOException) Notification(com.intellij.notification.Notification) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 4 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 5 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)

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