Search in sources :

Example 1 with PerlCommandLine

use of com.perl5.lang.perl.idea.execution.PerlCommandLine 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 2 with PerlCommandLine

use of com.perl5.lang.perl.idea.execution.PerlCommandLine in project Perl5-IDEA by Camelcade.

the class PerlDockerAdapter method buildBaseProcessCommandLine.

@NotNull
static PerlCommandLine buildBaseProcessCommandLine(@NotNull PerlCommandLine commandLine) {
    PerlCommandLine dockerCommandLine = baseCommandLine().withParameters(RUN, WITH_AUTOREMOVE, INTERACTIVELY).withParameters(WITH_ATTACHED, STDOUT, WITH_ATTACHED, STDERR, WITH_ATTACHED, STDIN).withCharset(commandLine.getCharset());
    if (commandLine.isUsePty()) {
        dockerCommandLine.withParameters(WITH_TTY);
        dockerCommandLine.withPty(true);
    }
    // mapping ports
    commandLine.getPortMappings().forEach(it -> dockerCommandLine.withParameters(EXPOSE_PORT, String.valueOf(it.getRemote()), PUBLISH_PORT, it.getLocal() + ":" + it.getRemote()));
    return dockerCommandLine;
}
Also used : PerlCommandLine(com.perl5.lang.perl.idea.execution.PerlCommandLine) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with PerlCommandLine

use of com.perl5.lang.perl.idea.execution.PerlCommandLine in project Perl5-IDEA by Camelcade.

the class PerlDockerAdapter method createCommandScript.

@NotNull
private File createCommandScript(@NotNull PerlCommandLine commandLine) throws ExecutionException {
    StringBuilder sb = new StringBuilder();
    commandLine.getEnvironment().forEach((key, val) -> sb.append("export ").append(key).append('=').append(CommandLineUtil.posixQuote(val)).append("\n"));
    sb.append(String.join(" ", ContainerUtil.map(commandLine.getCommandLineList(null), CommandLineUtil::posixQuote)));
    try {
        String command = sb.toString();
        LOG.debug("Executing in ", myData.getImageName());
        StringUtil.split(command, "\n").forEach(it -> LOG.debug("    ", it));
        var dockerWrapper = ExecUtil.createTempExecutableScript("dockerWrapper", "", command);
        LOG.debug("Created docker wrapper: ", dockerWrapper);
        return dockerWrapper;
    } catch (IOException e) {
        throw new ExecutionException(e);
    }
}
Also used : CommandLineUtil(com.intellij.execution.CommandLineUtil) IOException(java.io.IOException) ExecutionException(com.intellij.execution.ExecutionException) PerlExecutionException(com.perl5.lang.perl.idea.sdk.host.PerlExecutionException) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with PerlCommandLine

use of com.perl5.lang.perl.idea.execution.PerlCommandLine in project Perl5-IDEA by Camelcade.

the class PerlDockerData method fixPermissionsRecursively.

@Override
public void fixPermissionsRecursively(@NotNull String localPath, @Nullable Project project) throws ExecutionException {
    if (!SystemInfo.isUnix) {
        LOG.debug("Can fix permissions only on unix systems");
        return;
    }
    var remotePath = getRemotePath(localPath);
    if (remotePath == null) {
        LOG.warn("Unable to fix permissions, failed to map to remote path: " + localPath);
        return;
    }
    UnixSystem system = new UnixSystem();
    long gid = system.getGid();
    long uid = system.getUid();
    var chownOutput = execAndGetOutput(new PerlCommandLine("chown", "-R", uid + ":" + gid, remotePath).withProject(project).withHostData(this));
    LOG.debug("Executed permission change: ", chownOutput);
}
Also used : UnixSystem(com.sun.security.auth.module.UnixSystem) PerlCommandLine(com.perl5.lang.perl.idea.execution.PerlCommandLine)

Example 5 with PerlCommandLine

use of com.perl5.lang.perl.idea.execution.PerlCommandLine in project Perl5-IDEA by Camelcade.

the class PerlDockerData method findFileByName.

@Override
@Nullable
public File findFileByName(@NotNull String fileName) {
    try {
        ProcessOutput output = execAndGetOutput(new PerlCommandLine("\\which", fileName).withHostData(this));
        int exitCode = output.getExitCode();
        if (exitCode != 0 && exitCode != 1) {
            LOG.warn("Got non-zero code from script " + exitCode + "; stderr: " + output.getStderr());
            return null;
        }
        List<String> lines = output.getStdoutLines();
        return lines.isEmpty() ? null : new File(lines.get(0));
    } catch (ExecutionException e) {
        LOG.warn("Error seeking for " + fileName, e);
    }
    return null;
}
Also used : ProcessOutput(com.intellij.execution.process.ProcessOutput) PerlCommandLine(com.perl5.lang.perl.idea.execution.PerlCommandLine) ExecutionException(com.intellij.execution.ExecutionException) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PerlCommandLine (com.perl5.lang.perl.idea.execution.PerlCommandLine)19 VirtualFile (com.intellij.openapi.vfs.VirtualFile)12 ExecutionException (com.intellij.execution.ExecutionException)11 Project (com.intellij.openapi.project.Project)8 NotNull (org.jetbrains.annotations.NotNull)7 Nullable (org.jetbrains.annotations.Nullable)6 ProcessOutput (com.intellij.execution.process.ProcessOutput)5 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)3 ProcessEvent (com.intellij.execution.process.ProcessEvent)3 Notification (com.intellij.notification.Notification)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 Task (com.intellij.openapi.progress.Task)3 PerlSharedSettings (com.perl5.lang.perl.idea.configuration.settings.PerlSharedSettings)3 IOException (java.io.IOException)3 OutputStream (java.io.OutputStream)3 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)2 Document (com.intellij.openapi.editor.Document)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 PsiFile (com.intellij.psi.PsiFile)2 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)2