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;
}
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();
}
use of com.perl5.lang.perl.idea.sdk.host.PerlHostData in project Perl5-IDEA by Camelcade.
the class PerlBrewCreateLibraryAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Sdk perlSdk = PerlProjectManager.getSdk(e);
PerlBrewData perlBrewData = ObjectUtils.tryCast(PerlVersionManagerData.from(perlSdk), PerlBrewData.class);
if (perlBrewData == null) {
return;
}
PerlHostData<?, ?> hostData = PerlHostData.from(perlSdk);
if (hostData == null) {
return;
}
final String perlVersionString = perlBrewData.getPerlVersionString();
String libraryName = Messages.showInputDialog(getEventProject(e), PerlBundle.message("perl.vm.perlbrew.create.lib.message"), PerlBundle.message("perl.vm.perlbrew.create.lib.title", perlVersionString), null);
if (StringUtil.isEmpty(libraryName)) {
return;
}
new Task.Backgroundable(e.getProject(), PerlBundle.message("perl.vm.perlbrew.create.lib.progress", libraryName, perlVersionString)) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
PerlBrewAdapter perlBrewAdapter = new PerlBrewAdapter(perlBrewData.getVersionManagerPath(), hostData);
ProcessOutput processOutput = perlBrewAdapter.createLibrary(perlVersionString, libraryName);
if (processOutput == null) {
return;
}
String distirbutionId = perlVersionString + "@" + libraryName;
if (processOutput.getExitCode() == 0) {
doCreateSdk(perlBrewAdapter, distirbutionId);
}
if (StringUtil.contains(processOutput.getStderr(), "is already there")) {
Ref<Integer> resultRef = Ref.create(-1);
ApplicationManager.getApplication().invokeAndWait(() -> resultRef.set(Messages.showYesNoDialog(PerlBundle.message("perl.vm.perlbrew.library.exists", distirbutionId), PerlBundle.message("perl.vm.perlbrew.title"), PerlIcons.PERLBREW_ICON)));
if (Messages.YES == resultRef.get()) {
doCreateSdk(perlBrewAdapter, distirbutionId);
}
}
}
// fixme we could avoid creating duplicated sdks here
private void doCreateSdk(@NotNull PerlBrewAdapter perlBrewAdapter, @NotNull String distirbutionId) {
PerlBrewHandler.getInstance().createInterpreter(distirbutionId, perlBrewAdapter, sdk -> ApplicationManager.getApplication().invokeLater(() -> {
PerlBrewData perlBrewData = PerlBrewData.from(sdk);
if (perlBrewData != null && myProject != null && Messages.showYesNoDialog(myProject, PerlBundle.message("perl.vm.perlbrew.create.lib.select", perlBrewData.getDistributionId()), PerlBundle.message("perl.vm.perlbrew.create.lib.title", perlBrewData.getPerlVersionString()), null) == Messages.YES) {
PerlProjectManager.getInstance(myProject).setProjectSdk(sdk);
}
}), myProject);
}
}.queue();
}
use of com.perl5.lang.perl.idea.sdk.host.PerlHostData in project Perl5-IDEA by Camelcade.
the class PerlProfilerRunProfileState method getAdditionalEnvironmentVariables.
@Override
public Map<String, String> getAdditionalEnvironmentVariables() throws ExecutionException {
Sdk effectiveSdk = ((GenericPerlRunConfiguration) getEnvironment().getRunProfile()).getEffectiveSdk();
PerlHostData<?, ?> hostData = PerlHostData.notNullFrom(effectiveSdk);
var dumpLocalPath = getDumpFile().getAbsolutePath();
var remotePath = hostData.getRemotePath(dumpLocalPath);
if (StringUtil.isEmpty(remotePath)) {
throw new ExecutionException("Unable to compute remote path for: " + dumpLocalPath);
}
var nytProfOptions = "stmts=0:calls=2:savesrc=0:slowops=1:sigexit=1:addpid=1" + ":file=" + StringUtil.escapeChar(FileUtil.toSystemIndependentName(remotePath), ':') + ":start=" + myProfilerConfigurationState.getStartupMode().getProfilerCommand();
if (myProfilerConfigurationState.isOptimizerDisabled()) {
nytProfOptions += ":optimize=0";
}
return Map.of("NYTPROF", nytProfOptions);
}
use of com.perl5.lang.perl.idea.sdk.host.PerlHostData in project Perl5-IDEA by Camelcade.
the class PerlHostHandler method chooseFileInteractively.
/**
* Chooses a path conforming with {@code pathPredicate} on user-selected host and passes selected path and host data
* to the {@code selectionConsumer}
*
* @param defaultPathFunction function computing a default path from {@code hostData}
* @param useDefaultIfExists true if default path should be used silently if exists
* @param nameValidator restricts visible file names
* @param pathValidator validates a path selected by user and returns error message or null if everything is fine
* @param selectionConsumer a callback for selected result. Accepts path selected and the host data
* @param disposable session-bound things may be attached to this disposable, which is going to be disposed by parent configurable
*/
public void chooseFileInteractively(@NotNull String dialogTitle, @Nullable Function<PerlHostData<?, ?>, File> defaultPathFunction, boolean useDefaultIfExists, @NotNull Predicate<String> nameValidator, @NotNull Function<String, String> pathValidator, @NotNull BiConsumer<String, PerlHostData<?, ?>> selectionConsumer, @NotNull Disposable disposable) {
Data hostData = createDataInteractively();
if (hostData == null) {
return;
}
VirtualFileSystem fileSystem = hostData.getFileSystem(disposable);
File defaultPath = defaultPathFunction == null ? null : defaultPathFunction.apply(hostData);
Consumer<String> resultConsumer = it -> selectionConsumer.accept(it, hostData);
if (fileSystem != null) {
chooseFileInteractively(dialogTitle, defaultPath, useDefaultIfExists, nameValidator, pathValidator, resultConsumer, hostData, fileSystem);
} else {
chooseFileInteractively(dialogTitle, defaultPath, useDefaultIfExists, nameValidator, pathValidator, resultConsumer, hostData);
}
}
Aggregations