use of com.perl5.lang.perl.idea.sdk.host.os.PerlOsHandler in project Perl5-IDEA by Camelcade.
the class PerlRunUtil method findScript.
/**
* Attempts to find a script by name in perl's libraries path
*
* @param sdk perl sdk to search in
* @param scriptName script name to find
* @return script's virtual file if available
* @apiNote returns virtual file of local file, not remote
*/
@Contract("null,_->null; _,null->null")
@Nullable
public static VirtualFile findScript(@Nullable Sdk sdk, @Nullable String scriptName) {
if (sdk == null || StringUtil.isEmpty(scriptName)) {
return null;
}
ApplicationManager.getApplication().assertReadAccessAllowed();
PerlOsHandler osHandler = PerlOsHandler.notNullFrom(sdk);
return getBinDirectories(sdk).map(root -> {
VirtualFile scriptFile = null;
if (osHandler.isMsWindows()) {
scriptFile = root.findChild(scriptName + ".bat");
}
return scriptFile != null ? scriptFile : root.findChild(scriptName);
}).filter(Objects::nonNull).findFirst().orElse(null);
}
Aggregations