@Nullable public Project getEffectiveProject() { return myProject != null ? myProject : ObjectUtils.doIfNotNull(getModule(), Module::getProject); }
@Nullable public static PerlCommandLine getPerlCommandLine(@NotNull Project project, @Nullable Sdk perlSdk, @Nullable VirtualFile scriptFile, @NotNull List<String> perlParameters, @NotNull List<String> scriptParameters) { if (perlSdk == null) { perlSdk = PerlProjectManager.getSdk(project, scriptFile); } return getPerlCommandLine(project, perlSdk, ObjectUtils.doIfNotNull(scriptFile, VirtualFile::getPath), perlParameters, scriptParameters); }
@Contract("null->null") @Nullable public static PerlHostData<?, ?> from(@Nullable Sdk sdk) { return ObjectUtils.doIfNotNull(PerlSdkAdditionalData.from(sdk), PerlSdkAdditionalData::getHostData); }
@Contract("null->null") @Nullable public static PerlVersionManagerData<?, ?> from(@Nullable Sdk sdk) { return ObjectUtils.doIfNotNull(PerlSdkAdditionalData.from(sdk), PerlSdkAdditionalData::getVersionManagerData); }
@Contract("null->null") @Nullable public static PerlOsHandler from(@Nullable Sdk sdk) { return ObjectUtils.doIfNotNull(PerlHostData.from(sdk), PerlHostData::getOsHandler); } }
@Contract("null->null") @Nullable static PerlImplementationData from(@Nullable Sdk sdk) { return ObjectUtils.doIfNotNull(PerlSdkAdditionalData.from(sdk), PerlSdkAdditionalData::getImplementationData); } }
/** * @return container of closest parent block for the {@code position} */ @Contract("null -> null") @Nullable static PsiElement getClosestBlockCompoundContainer(@Nullable PsiElement position) { return ObjectUtils.doIfNotNull(getClosestTo(position), PerlBlock::getCompoundContainer); } }
/** * Attempts to find a script in project's perl sdk and shows notification to user with suggestion to install a library if * script was not found * * @param project to get sdk from * @param scriptName script name * @param libraryName library to suggest if script was not found; notification won't be shown if lib is null/empty * @return script's virtual file if any */ @Nullable public static VirtualFile findLibraryScriptWithNotification(@NotNull Project project, @NotNull String scriptName, @Nullable String libraryName) { return ObjectUtils.doIfNotNull( PerlProjectManager.getSdkWithNotification(project), it -> findLibraryScriptWithNotification(it, project, scriptName, libraryName)); }
@Nullable WSLDistributionWithRoot getDistribution() { return ObjectUtils.doIfNotNull(WSLUtil.getDistributionById(getDistributionId()), WSLDistributionWithRoot::new); }
@Nullable @Override public String getPodLinkText() { String normalizedPackageName = getNormalizedPackageName(); if (StringUtil.isNotEmpty(normalizedPackageName)) { return normalizedPackageName; } return ObjectUtils.doIfNotNull(getVirtualFile(), VirtualFile::getName); }
@Nullable @Override public String getVersionString(@NotNull Sdk sdk) { return ObjectUtils.doIfNotNull( getPerlVersionDescriptor(PerlProjectManager.getInterpreterPath(sdk), PerlHostData.notNullFrom(sdk), PerlVersionManagerData.notNullFrom(sdk)), VersionDescriptor::getVersionString); }
/** * @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(); }
private PerlCommandLine patchCommandLine(@NotNull PerlCommandLine perlCommandLine) throws ExecutionException { WSLDistributionWithRoot distribution = getDistribution(); if (distribution == null) { throw new ExecutionException(PerlWslBundle.message("perl.host.handler.distribution.unavailable", getDistributionId())); } String workingDir = ObjectUtils.doIfNotNull(perlCommandLine.getWorkDirectory(), File::toString); perlCommandLine.withWorkDirectory((String)null); return distribution.patchCommandLine( perlCommandLine, perlCommandLine.getEffectiveProject(), getRemotePath(workingDir), false); }
@Override protected void applyEditorTo(@NotNull PerlRunConfiguration perlRunConfiguration) throws ConfigurationException { perlRunConfiguration.setScriptPath(myScriptField.getText()); myParametersPanel.applyTo(perlRunConfiguration); perlRunConfiguration.setConsoleCharset(StringUtil.nullize((String)myConsoleCharset.getSelectedItem(), true)); perlRunConfiguration.setPerlParameters(myPerlParametersPanel.getText()); perlRunConfiguration.setUseAlternativeSdk(myAlternativeSdkCheckbox.isSelected()); mySdkConfigurable.apply(); perlRunConfiguration.setAlternativeSdkName(ObjectUtils.doIfNotNull(mySdkProxy, Sdk::getName)); super.applyEditorTo(perlRunConfiguration); }