use of com.perl5.lang.perl.idea.sdk.host.PerlHostFileTransfer in project Perl5-IDEA by Camelcade.
the class PerlSdkType method setupSdkPaths.
@Override
public void setupSdkPaths(@NotNull Sdk sdk) {
if (ApplicationManager.getApplication().isDispatchThread() && !ApplicationManager.getApplication().isHeadlessEnvironment()) {
throw new RuntimeException("Do not call from EDT, refreshes FS");
}
String oldText = PerlRunUtil.setProgressText(PerlBundle.message("perl.progress.refreshing.inc", sdk.getName()));
LOG.info("Refreshing @INC for " + sdk);
PerlHostData<?, ?> hostData = PerlHostData.notNullFrom(sdk);
List<String> pathsToRefresh = new ArrayList<>();
// syncing data if necessary
List<String> incPaths = computeIncPaths(sdk);
List<Exception> exceptions = new ArrayList<>();
try (PerlHostFileTransfer<?> fileTransfer = hostData.getFileTransfer()) {
Consumer<File> downloader = it -> syncAndCollectException(fileTransfer, it, pathsToRefresh, exceptions, false);
Consumer<File> binStubber = it -> syncAndCollectException(fileTransfer, it, pathsToRefresh, exceptions, true);
for (String hostPath : incPaths) {
downloader.accept(new File(hostPath));
binStubber.accept(PerlRunUtil.findLibsBin(new File(hostPath)));
}
// additional bin dirs from version manager
PerlVersionManagerData.notNullFrom(sdk).getBinDirsPath().forEach(binStubber);
// sdk home path
File interpreterPath = new File(Objects.requireNonNull(PerlProjectManager.getInterpreterPath(sdk)));
binStubber.accept(interpreterPath.getParentFile());
List<VirtualFile> filesToRefresh = pathsToRefresh.stream().map(it -> VfsUtil.findFileByIoFile(new File(it), true)).filter(Objects::nonNull).collect(Collectors.toList());
if (!filesToRefresh.isEmpty()) {
PerlRunUtil.setProgressText(PerlBundle.message("perl.progress.refreshing.filesystem"));
VfsUtil.markDirtyAndRefresh(false, true, true, filesToRefresh.toArray(VirtualFile.EMPTY_ARRAY));
}
try {
fileTransfer.syncHelpers();
} catch (IOException e) {
exceptions.add(e);
}
if (!exceptions.isEmpty()) {
int copiedFiles = filesToRefresh.size();
int errorsNumber = exceptions.size();
Notifications.Bus.notify(new Notification(PerlBundle.message("perl.sync.notification.group"), PerlBundle.message("perl.sync.notification.title"), PerlBundle.message("perl.sync.notification.body", copiedFiles, copiedFiles + errorsNumber, errorsNumber, StringUtil.pluralize(PerlBundle.message("perl.sync.notification.pluralize"), errorsNumber)), NotificationType.ERROR));
exceptions.forEach(LOG::warn);
}
} catch (IOException e) {
LOG.warn("Error closing transfer for " + sdk, e);
}
// updating sdk
SdkModificator sdkModificator = sdk.getSdkModificator();
sdkModificator.removeAllRoots();
for (String hostPath : incPaths) {
String localPath = hostData.getLocalPath(hostPath);
if (localPath == null) {
continue;
}
File libDir = new File(localPath);
if (libDir.exists() && libDir.isDirectory()) {
VirtualFile virtualDir = VfsUtil.findFileByIoFile(libDir, true);
if (virtualDir != null) {
sdkModificator.addRoot(virtualDir, OrderRootType.CLASSES);
}
}
}
ApplicationManager.getApplication().invokeAndWait(sdkModificator::commitChanges);
PerlRunUtil.setProgressText(oldText);
}
Aggregations