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;
}
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;
}
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);
}
}
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);
}
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;
}
Aggregations