use of com.perl5.lang.perl.idea.sdk.host.PerlHostData in project Perl5-IDEA by Camelcade.
the class PerlTestRunConfiguration method createBaseCommandLine.
@Override
@NotNull
protected PerlCommandLine createBaseCommandLine(@NotNull PerlRunProfileState perlRunProfileState) throws ExecutionException {
ExecutionEnvironment executionEnvironment = perlRunProfileState.getEnvironment();
Project project = executionEnvironment.getProject();
List<String> additionalPerlParameters = perlRunProfileState.getAdditionalPerlParameters(this);
Map<String, String> additionalEnvironmentVariables = perlRunProfileState.getAdditionalEnvironmentVariables();
Sdk perlSdk = getEffectiveSdk();
VirtualFile proveScript = PerlRunUtil.findLibraryScriptWithNotification(perlSdk, getProject(), PROVE, TEST_HARNESS);
if (proveScript == null) {
throw new ExecutionException(PerlBundle.message("perl.run.error.prove.missing", perlSdk.getName()));
}
PerlHostData<?, ?> perlHostData = PerlHostData.notNullFrom(perlSdk);
Set<String> proveParameters = new LinkedHashSet<>(PROVE_DEFAULT_PARAMETERS);
proveParameters.addAll(getScriptParameters());
proveParameters.add(PROVE_JOBS_PARAMETER);
proveParameters.add(Integer.toString(perlRunProfileState.isParallelRunAllowed() ? getJobsNumber() : 1));
VirtualFile workingDirectory = computeExplicitWorkingDirectory();
List<String> testsPaths = new ArrayList<>();
for (VirtualFile testVirtualFile : computeTargetFiles()) {
if (testVirtualFile == null) {
continue;
}
String virtualFilePath = testVirtualFile.getPath();
if (workingDirectory != null && VfsUtil.isAncestor(workingDirectory, testVirtualFile, true)) {
testsPaths.add(VfsUtil.getRelativePath(testVirtualFile, workingDirectory));
} else {
testsPaths.add(perlHostData.getRemotePath(virtualFilePath));
}
}
String remotePath = perlHostData.getRemotePath(proveScript.getPath());
if (StringUtil.isEmpty(remotePath)) {
throw new ExecutionException("Unable to map remote path: " + remotePath + " for " + perlHostData);
}
PerlCommandLine commandLine = new PerlCommandLine(getEffectiveInterpreterPath()).withParameters(remotePath).withParameters(proveParameters).withParameters(testsPaths).withProject(project).withSdk(perlSdk);
List<String> testScriptParametersList = getTestScriptParametersList();
if (!testScriptParametersList.isEmpty()) {
commandLine.withParameters("::");
commandLine.withParameters(testScriptParametersList);
}
ArrayList<String> perlParametersList = new ArrayList<>(getPerlParametersList());
perlParametersList.addAll(additionalPerlParameters);
for (VirtualFile libRoot : PerlProjectManager.getInstance(project).getModulesLibraryRoots()) {
perlParametersList.add(PERL_I + perlHostData.getRemotePath(libRoot.getCanonicalPath()));
}
// environment
Map<String, String> environment = new HashMap<>(getEnvs());
environment.putAll(additionalEnvironmentVariables);
if (!perlParametersList.isEmpty()) {
String currentOpt = environment.get(PerlRunUtil.PERL5OPT);
if (StringUtil.isNotEmpty(currentOpt)) {
perlParametersList.addAll(0, StringUtil.split(currentOpt, " "));
}
environment.put(PerlRunUtil.PERL5OPT, StringUtil.join(perlParametersList, " "));
}
environment.forEach((key, val) -> commandLine.withEnvironment(PROVE_PASS_PREFIX + key, val));
commandLine.withParentEnvironmentType(isPassParentEnvs() ? CONSOLE : NONE);
return commandLine;
}
use of com.perl5.lang.perl.idea.sdk.host.PerlHostData in project Perl5-IDEA by Camelcade.
the class InstallPerlHandler method doInstall.
void doInstall(@NotNull PerlHostData<?, ?> hostData, @Nullable Project project) {
if (ApplicationManager.getApplication().isDispatchThread()) {
throw new RuntimeException("Should not be invoked on EDT");
}
PerlVersionManagerAdapter vmAdapter = createAdapter(myVersionManagerPath, hostData);
PerlRunUtil.setProgressText(PerlBundle.message("perl.vm.fetching.available.perls"));
List<String> distributionsList = vmAdapter.getInstallableDistributionsList();
if (distributionsList == null) {
return;
}
ApplicationManager.getApplication().invokeLater(() -> {
PerlInstallFormOptions optionsForm = createOptionsForm();
MyDialog dialog = new MyDialog(project, optionsForm, distributionsList);
if (dialog.showAndGet()) {
PerlInstallForm installForm = dialog.getForm();
boolean createInterpreter = installForm.isAddInstalledPerl();
boolean chooseInterpreter = installForm.isChooseInstalledPerl();
String distributionId = installForm.getSelectedDistributionId();
String targetName = optionsForm.getTargetName(distributionId);
vmAdapter.installPerl(project, distributionId, optionsForm.buildParametersList(), new ProcessAdapter() {
@Override
public void processTerminated(@NotNull ProcessEvent event) {
if (!createInterpreter || event.getExitCode() != 0) {
return;
}
myVersionManageHandler.createInterpreter(targetName, vmAdapter, sdk -> {
if (chooseInterpreter && project != null) {
ApplicationManager.getApplication().invokeLater(() -> PerlProjectManager.getInstance(project).setProjectSdk(sdk));
}
}, project);
}
});
}
});
}
Aggregations